我试图在(Neon)中运行一个非常简单的C++应用程序:程序启动,显示红色的显示,10秒后关闭自己。
为了实现这一点,我正在运行Allero5.0.10游戏引擎,它的源代码在/usr/local/include/allegro5中安装了一些库。我的程序是这样的:
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro5.h>
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(255,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}使用以下选项从头创建一个新项目.

...and用这些.


...when选择“Build”,控制台中会出现一条错误消息:
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: pang
Invoking: GCC C++ Linker
g++ `pkg-config --libs allegro-5 allegro_image-5` -o "pang" ./main.o
./main.o: In function `main':
/home/xvlaze/workspace/pang/Debug/../main.cpp:14: undefined reference to `al_install_system'
/home/xvlaze/workspace/pang/Debug/../main.cpp:19: undefined reference to `al_create_display'
/home/xvlaze/workspace/pang/Debug/../main.cpp:25: undefined reference to `al_map_rgb'
/home/xvlaze/workspace/pang/Debug/../main.cpp:25: undefined reference to `al_clear_to_color'
/home/xvlaze/workspace/pang/Debug/../main.cpp:27: undefined reference to `al_flip_display'
/home/xvlaze/workspace/pang/Debug/../main.cpp:29: undefined reference to `al_rest'
/home/xvlaze/workspace/pang/Debug/../main.cpp:31: undefined reference to `al_destroy_display'
collect2: error: ld returned 1 exit status
make: *** [pang] Error 1EXTRA:,我已经复制了this的答案,但它仍然不起作用。
发布于 2016-09-19 21:02:24
您现在遇到的问题是,您添加的特殊标志出现在依赖它们的对象之前。
您应该做的是更改GCC C链接器->命令行模式,使${FLAGS}在${INPUTS}之后具有。
这样做会将编译行从以下位置更改:
g++ `pkg-config --libs allegro-5 allegro_image-5` -o "pang" ./main.o 至:
g++ -o "pang" ./main.o `pkg-config --libs allegro-5 allegro_image-5` 有关链接顺序和重要原因的更多信息,请参见https://stackoverflow.com/a/409470/2796832。
https://stackoverflow.com/questions/39563323
复制相似问题