C++ 编译器检测allegro.h,但不检测allegro_原语.h

C++ 编译器检测allegro.h,但不检测allegro_原语.h,c++,ubuntu,g++,allegro,C++,Ubuntu,G++,Allegro,当我使用g++编译Allegro 5程序时,它抱怨未定义对“al_init_primitives_addon”、al_draw_filled_rectangle以及在Allegro_primitives.h中找到的其他类似函数的引用。它不会抱怨allegro.h中的函数,比如al\u create\u display 包括: #include <allegro5/allegro.h> #include <allegro5/allegro_primitives.h> #

当我使用g++编译Allegro 5程序时,它抱怨
未定义对“al_init_primitives_addon”、al_draw_filled_rectangle
以及在Allegro_primitives.h中找到的其他类似函数的引用。它不会抱怨allegro.h中的函数,比如
al\u create\u display

包括:

#include <allegro5/allegro.h>

#include <allegro5/allegro_primitives.h>

#include "objects.h"

#include "main.h"
投诉:

/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++编译得很好。

您的
-lallegro
不包含这些函数。如果在系统路径中有一个旧库,在
/usr/lib/allegro 5
中有一个所需的5.x库,则需要在
-L
之前传递
-L

您需要链接allegro和allegro_原语。正确的方法是:

g++ main.cpp -o game $(pkg-config --libs 
   allegro-5.0 allegro_main-5.0 allegro_primitives-5.0)
(当然,都在一条线上。)


.pc文件将位于
/usr/local/lib/pkgconfig
中,它需要位于环境变量
PKG\u CONFIG\u路径中。

g++main.cpp-o game-I/usr/include/allegro5-L/usr/lib/allegro5-lallegro?这给了我同样的错误。
g++ main.cpp -o game $(pkg-config --libs 
   allegro-5.0 allegro_main-5.0 allegro_primitives-5.0)