简体   繁体   English

我无法运行将Allegro5与cmake结合使用的程序

[英]I can't run a program that uses allegro5 with cmake

EDIT: If you want to look at the code, here it is: https://github.com/WalterCapa/PercolationCpp/tree/master 编辑:如果您想看代码,在这里是: https : //github.com/WalterCapa/PercolationCpp/tree/master

I'm making a program that uses allegro5 library to generate an animation. 我正在制作一个使用allegro5库生成动画的程序。 Because i want to avoid the installation of the library on every computer that uses the program, i tried to paste the headers and the .so files in my project dir. 因为我想避免在使用该程序的每台计算机上安装该库,所以我尝试将标头和.so文件粘贴到我的项目目录中。 So the tree is like this: 所以树是这样的:

root

include
  allegro5  <- (Dir where the headers of allegro are)
  Percolation.h
  QuickUnion.h

lib
  allegro5  <-(Dir where the .so files are)
  Percolation.cpp
  QuickUnion.cpp

PercolationVisualizer <- (Dir that has the main)

The problem is this. 问题是这样的。 I installed allegro5 in my pc with LinuxMint 13. Everything is fine if I compile from Code::Blocks or if I do it from the terminal using -I to call the hedaers and -L to tell where the .so files are, and even using cmake works fine, but when i try to do it in another computer, even if it's windows like my laptop or a virtual machine with linuxmint, it generates this error: 我在装有LinuxMint 13的PC上安装了allegro5。如果我从Code :: Blocks进行编译,或者使用-I调用hedaers和-L来告知.so文件在哪里,甚至从终端执行此操作,一切都很好。使用cmake可以很好地工作,但是当我尝试在另一台计算机上执行该操作时,即使它是Windows之类的笔记本电脑或带有linuxmint的虚拟机,它也会产生此错误:

make[2]: *** No rule to make target  '/./lib/allegro5/liballegro.so/', needed by'
../bin/PercolationVisualizer'.   Stop.
make[1]: *** [CMakeFiles/PercolationVisualizer.dir/all] Error 2
make: *** [all] Error 2

This is my CMakeLists.txt: 这是我的CMakeLists.txt:

    cmake_minimum_required(VERSION 2.8.7)
    project(PercolationCpp)

    set(PercolationCpp_VERSION_MAJOR 0)
    set(PercolationCpp_VERSION_MINOR 1)

    set(EXECUTABLE_OUTPUT_PATH ../bin/)

    set(percolation_SRCS PercolationVisualizer/PercolationVisualizer.cpp lib/Percolation.cpp lib/QuickUnion.cpp)

    #Executable 
    add_executable(PercolationVisualizer  ${percolation_SRCS})

    #include Allegro
    include_directories(./include)
    link_directories(./lib/allegro5)
    #connect all the libraries
    set(allegro5_LIBS /./lib/allegro5/liballegro.so /./lib/allegro5/liballegro_primitives.so)

    target_link_libraries(PercolationVisualizer ${allegro5_LIBS})

Btw, when trying it on windows with MinGW i used cmake -G "MinGW Makefiles" .. and mingw32-make. 顺便说一句,当在Windows上使用MinGW尝试时,我使用了cmake -G“ MinGW Makefiles” ..和mingw32-make。 It found the compiler and and cmake worked, but when i tried de second one it gave me the same error. 它发现编译器和cmake都起作用,但是当我尝试第二次尝试时,它给了我同样的错误。 In my desktop i'm compiling using g++. 在我的桌面上,我正在使用g ++进行编译。

I think that your actual problem is the leading / in this line: 我认为您的实际问题是这条线的领先/

set(allegro5_LIBS /./lib/allegro5/liballegro.so /./lib/allegro5/liballegro_primitives.so)

A leading slash will tell cmake to look for an absolute path (like /usr/lib...) and not prefix it with a CMAKE_*_DIR . 前导斜杠将指示cmake查找绝对路径(例如/ usr / lib ...),而不在其CMAKE_*_DIR加上CMAKE_*_DIR前缀。 Try this 尝试这个

set(allegro5_LIBS ${CMAKE_SOURCE_DIR}/lib/allegro5/liballegro.so ${CMAKE_SOURCE_DIR}/lib/allegro5/liballegro_primitives.so)

However I strong discourage you to include pre-built libraries in your project. 但是,我强烈建议您在项目中包括预构建的库。 If you can, integrate a tar-ball or a git-submodule. 如果可以,请集成tar球或git子模块。 If the project you include is a cmake project itself, a simple call to add_subdirectory will make the targets (libraries usually) available to your project and create a dependency. 如果您包含的项目本身是cmake项目,则对add_subdirectory的简单调用将使目标(通常是库)可用于您的项目并创建依赖项。 If the project is based on configure you can use the ExternalProject -extension. 如果项目基于configure,则可以使用ExternalProject -extension。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM