所以很久以前我在上做了一个游戏。两年前,我把这些资料上传到github NEGU93 93/福比德登沙漠,只是为了让它在那里。现在我从windows变成了linux,我想回去为linux编译这个游戏。
我记得我在GUI中使用了快板,所以我按照下面的步骤安装快板5安装了它。当我编码游戏时,我记得直接下载了一个为Visual准备的快板,所以我没有任何问题。
我创建了一个CMakeLists.txt (以前从未这样做过,所以我在这方面很新):
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 2.8)
# projects name
project(ForbiddenDesert)
set(CMAKE_CXX_STANDARD 11) # enable C++11 standard
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
# Finds Allegro using pkgconfig, so it must be configured correctly
find_package(Allegro5 REQUIRED)
# Set include and lib dirs.
include_directories(${ALLEGRO_INCLUDE_DIR})
set(FD_LIBS ${LIBS} ${OBJC_LIBRARIES} ${ALLEGRO_LIBRARIES})
# The following folder will be included
# include_directories(${PROJECT_SOURCE_DIR}/src)
# include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories("${PROJECT_SOURCE_DIR}")
file(GLOB all_SRCS
"*.h"
"*.cpp"
)
add_executable(forbidden ${all_SRCS})
target_link_libraries(forbidden ${FD_LIBS})我在名为FindAllegro5.cmake的文件夹中使用名为cmake/的文件。该文件是eruta/FindAllegro5.cmake的副本。
在运行cmake .时,我得到以下信息:
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'allegro-5'
-- Found allegro-5, version 5.2.4
-- Found Allegro5: /usr/lib/liballegro.so;/usr/lib/liballegro_image.so;/usr/lib/liballegro_font.so;/usr/lib/liballegro_primitives.so;/usr/lib/liballegro_ttf.so;/usr/lib/liballegro_audio.so;/usr/lib/liballegro_dialog.so;/usr/lib/liballegro_memfile.so;/usr/lib/liballegro_acodec.so;/usr/lib/liballegro_color.so;/usr/lib/liballegro_main.so;/usr/lib/liballegro_physfs.so 到目前一切尚好。但是,当我运行make时
In file included from /home/ubuntu/Documents/GitHub/ForbiddenDesert/Button.h:5:0,
from /home/ubuntu/Documents/GitHub/ForbiddenDesert/ArcheologistButton.h:4,
from /home/ubuntu/Documents/GitHub/ForbiddenDesert/ArcheologistButton.cpp:1:
/home/ubuntu/Documents/GitHub/ForbiddenDesert/allegro.h:5:10: fatal error: allegro5\allegro.h: No such file or directory
#include <allegro5\allegro.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/forbidden.dir/build.make:62: recipe for target 'CMakeFiles/forbidden.dir/ArcheologistButton.cpp.o' failed
make[2]: *** [CMakeFiles/forbidden.dir/ArcheologistButton.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/forbidden.dir/all' failed
make[1]: *** [CMakeFiles/forbidden.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2我已经看到FindAllegro5.cmake有:
# Include dir
find_path(Allegro5_INCLUDE_DIR
NAMES allegro5/allegro5.h
PATHS ${Allegro5_PKGCONF_INCLUDE_DIRS}
)因此,我将包含更改为#include <allegro5/allegro5.h>,但仍然没有解决方案。
我还没有找到解决方案(我找到了大量关于“致命错误:寓言5\寓言。h:没有这样的文件或目录”的信息,但没有找到适用于我的情况的解决方案)。
所以我安装了下面的快板:快车快板,然后我创建了hello.c文件,并按照它的意思编译它(gcc hello.c -o hello $(pkg-config allegro-5 allegro_font-5 --libs --cflags)),并且它工作了。因此,问题将是如何将这些标志添加到cmakelists.txt
所以我试着:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $(pkg-config allegro-5 allegro_font-5 allegro_primitives-5 allegro_ttf-5 allegro_image-5 allegro_audio-5 allegro_acodec-5 --libs --cflags)")但还是没用。
运行find /usr/ -name "allegro*"时,我在/usr/include/allegro5/allegro5.h上找到了头部allegro5.h,在/usr/lib/pkgconfig/上找到了其他一些文件。所以我做了:
INCLUDE_DIRECTORIES( /usr/include/allegro5 )
LINK_DIRECTORIES( /usr/lib/pkgconfig )
TARGET_LINK_LIBRARIES(game liballegro.a )还是不起作用。
我尝试从我从github上编译的源代码中直接添加库(遵循我在这里找到的信息,快板与CMake),但仍然没有工作:
#Include Allegro
include_directories(/home/ubuntu/Documents/GitHub/allegro5/build/include)
include_directories(/home/ubuntu/Documents/GitHub/allegro5/build/lib/Headers)
link_directories(/home/ubuntu/Documents/GitHub/allegro5/build/lib)
#connect all the libraries you need
set(game_LIBS liballegro.so liballegro_dialog.so liballegro_image.so)
target_link_libraries(game ${game_LIBS})发布于 2018-10-15 01:53:02
在Ubuntu下,我只需安装带有apt-get的快板
apt-get install liballegro5-dev然后包含在正确的位置(/usr/include/allegro5/...)
你说你安装了快板,但我不太确定它会不会和包一样。如果是来自构建,那么默认安装目录通常是/usr/local而不是/usr。所以包含将出现在/usr/local/include/allegro5/...中
尽管如此,cmake中的include()命令是正确的:
include_directories(${ALLEGRO_INCLUDE_DIR})但是,您的库处理是完全错误的。你永远不必改变LD_FLAGS。(至少,在过去的6到7年里,我使用了cmake,我从来没有什么需要。)相反,您希望使用target_link_libraries()。就像这样:
target_link_libraries(${PROJECT_NAME} ${ALLEGRO_LIBRARIES})它将在(如后面的) project(...)中工作。
如果要验证变量的名称是否正确,可以使用message()命令。一些库使用诸如NAME_LIBRARY或NAME_INCLUDE_PATH之类的名称。他们应该遵循正确的命名规则,但是没有什么强迫他们这样做,所以你经常会发现一些奇怪的地方。
以下内容将打印出一条消息:
message("allegro libraries = " ${ALLEGRO_LIBRARIES})如果变量名不正确(或者没有找到库),您将什么也看不到。如果您做对了,它将向您展示变量库。我想这是对的,但LD_FLAGS可能是你错了。
https://stackoverflow.com/questions/52804767
复制相似问题