c++ - 我无法运行将 allegro5 与 cmake 结合使用的程序

标签 c++ g++ cmake allegro5

编辑:如果你想看代码,这里是: https://github.com/WalterCapa/PercolationCpp/tree/master

我正在制作一个使用 allegro5 库生成动画的程序。 因为我想避免在每台使用该程序的计算机上安装库,所以我尝试将 header 和 .so 文件粘贴到我的项目目录中。所以树是这样的:

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)

问题是这样的。我使用 LinuxMint 13 在我的电脑上安装 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

这是我的 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})

顺便说一句,在使用 MinGW 的 Windows 上尝试时,我使用了 cmake -G "MinGW Makefiles".. 和 mingw32-make。 它发现编译器和 cmake 工作正常,但是当我尝试第二个时,它给了我同样的错误。在我的桌面上,我正在使用 g++ 进行编译。

最佳答案

我认为您的实际问题是这一行中的前导 /:

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

前导斜杠将告诉 cmake 寻找绝对路径(如/usr/lib...),而不是使用 CMAKE_*_DIR 作为前缀。试试这个

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

但是,我强烈建议您在项目中包含预构建的库。如果可以,集成一个 tar-ball 或 git-submodule。如果您包含的项目本身是一个 cmake 项目,则对 add_subdirectory 的简单调用将使目标(通常是库)可用于您的项目并创建依赖项。如果项目基于配置,您可以使用 ExternalProject -扩展名。

关于c++ - 我无法运行将 allegro5 与 cmake 结合使用的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21070517/

相关文章:

c++ - 从main.cpp中分离一些函数时出现 "undefined symbols for architecture"错误,怎么办?

c++ - CMake 标志更改调试配置

c++ - 如何使指针指向第二个数组中的字符

c++ - Microsoft Visual C++ 代码优化

c++ - 机器类型(C++ 库): i386 vs x86_64

c++ - 如何让程序确定最大的用户输入

linux - 如何为 aCC (Hp-Ux) 和 g++ (Linux) 获得相同的预处理器输出?

c++ - 私有(private)转换函数导致 "ambiguous default type conversion"错误 (c++)

c++ - 如何在 cmake >= 2.6 中使用没有 gnu 扩展的 c++98?

file - 如何使用 CMake 将多个文件列表合并在一起?