Compiler detects allegro.h, but not allegro_primitives.h

杀马特。学长 韩版系。学妹 提交于 2019-12-10 23:50:12

问题


When I compile my Allegro 5 program using g++, it complains about undefined reference to 'al_init_primitives_addon', al_draw_filled_rectangle and other such functions that are found in allegro_primitives.h. It does not complain about functions in allegro.h like al_create_display.

Includes:

#include <allegro5/allegro.h>

#include <allegro5/allegro_primitives.h>

#include "objects.h"

#include "main.h"

Compiler command:

g++ main.cpp -o game -lallegro -I/usr/include/allegro5 -L/usr/lib/allegro5

Complaints:

/tmp/ccAyQlcl.o: In function `main':
main.cpp:(.text+0xef): undefined reference to `al_init_primitives_addon'
/tmp/ccAyQlcl.o: In function `Draw()':
main.cpp:(.text+0x38c): undefined reference to `al_draw_filled_rectangle'
main.cpp:(.text+0x415): undefined reference to `al_draw_filled_rectangle'

MSVC++ compiles this fine, by the way.


回答1:


You need to link with allegro and allegro_primitives. The proper way is:

g++ main.cpp -o game $(pkg-config --libs 
   allegro-5.0 allegro_main-5.0 allegro_primitives-5.0)

(All on one line, of course.)

The .pc files will be in /usr/local/lib/pkgconfig which needs to be in your PKG_CONFIG_PATH environment variable.




回答2:


Your -lallegro doesn't contain these functions. If you have an old library in system paths and the needed 5.x one in /usr/lib/allegro5, you need to pass your -L before -l.



来源:https://stackoverflow.com/questions/8698180/compiler-detects-allegro-h-but-not-allegro-primitives-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!