![](/img/trans.png)
[英]Error: Assertation failed allegro5\addons\font\text.c line 77 expression font
[英]Problems referencing Allegro5 addons
我正在嘗試在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)
我究竟做錯了什么?
正如您在錯誤中看到的那樣,在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”即可使其起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.