我正在尝试在CLion中使用Allegro5,但我不能引用插件,尽管它可以找到头文件和lib文件。
我有“/ usr / lib”中的库和“/ usr / include”中的头文件,此外,我在proyect目录中有库和头文件。
我可以使用并编译它:
[..]
al_set_window_title(display, "title");
al_clear_to_color(al_map_rgb(4,0,90));
ALLEGRO_COLOR electric_blue = al_map_rgb(44, 117, 255);
但是我无法编译它(尽管检测到标题和函数):
#include <allegro5/allegro_primitives.h>
[..]
al_draw_line(100,500,300,500,electric_blue,6.0);
这是错误:
Scanning dependencies of target project
[ 9%] Building CXX object CMakeFiles/project.dir/main.cpp.o
[ 18%] Linking CXX executable project
CMakeFiles/project.dir/main.cpp.o: En la función `main':
/home/lifka/Desktop/tetris/project/main.cpp:80: reference to `al_draw_line' undefined
collect2: error: ld devolvió el estado de salida 1
make[2]: *** [CMakeFiles/project.dir/build.make:329: project] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/project.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
这是CMakeList.txt:
cmake_minimum_required(VERSION 3.7)
project(project)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp [..])
SET(ALLEGRO_ROOT allegro/)
INCLUDE_DIRECTORIES( ${ALLEGRO_ROOT}/include)
LINK_DIRECTORIES( /${ALLEGRO_ROOT}/lib )
add_executable(project ${SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(project PUBLIC ${ALLEGRO_ROOT})
TARGET_LINK_LIBRARIES(project allegro)
我做错了什么?
答案 0 :(得分:0)
正如您在错误中看到的那样,main.cpp:80中对'al_draw_line'的引用未定义。这是因为Allegro有很多插件,如果你使用它们,你也必须链接它们。
要解决此问题,请替换
TARGET_LINK_LIBRARIES(project allegro)
通过
TARGET_LINK_LIBRARIES(project
allegro_acodec
allegro_audio
allegro_color
allegro_dialog
allegro_image
allegro_main
allegro_memfile
allegro_physfs
allegro_primitives
allegro_ttf
allegro_font
allegro)
或者只使用您需要的任何插件制作列表。在这种情况下,例如,对于使用'al_draw_line',您只需要'allegro_primitives'即可使其正常工作。