简体   繁体   English

Allegro 5.0 - 为什么我会收到链接器错误?

[英]Allegro 5.0 - why am I getting linker errors?

I recently compiled Allegro-5.0 from source (following the instructions from the wiki). 我最近从源代码编译了Allegro-5.0(遵循wiki的说明)。 I didn't get any errors during the process, so I assume it went well. 我在这个过程中没有遇到任何错误,所以我认为它进展顺利。 However, I am getting linker errors with even the most minimal test programs: 但是,即使是最小的测试程序,我也会遇到链接器错误:

//test.cpp
#include <allegro5/allegro.h>

int main()
{
    al_init();
    return 0;
}

I am compiling with 我正在编译

g++ `pkg-config --libs allegro-5.0` test.cpp -o test

But I always get 但我总是得到

/tmp/ccVmmERa.o: In function `main':
test.cpp:(.text+0xf): undefined reference to `al_install_system'
collect2: error: ld returned 1 exit status

(pkg-config returns -L/usr/local/lib -lallegro, there doesn't seem to be anything wrong with that) (pkg-config返回-L / usr / local / lib -lallegro,似乎没有任何问题)

Also, I can compile the examples with the the given makefile just fine, so there doesn't seem to be anything wrong with the library. 另外,我可以使用给定的makefile编译示例,因此库似乎没有任何问题。 I would just try to do the same thing the makefile does to make it work, but I don't understand it at all (I can barely write my own simple ones). 我只是尝试做同样的事情,makefile使它工作,但我根本不理解它(我几乎不能写我自己的简单)。

Oh, and I'm using Ubuntu 11.10 and gcc 4.7, though I don't think that has anything to do with it. 哦,我正在使用Ubuntu 11.10和gcc 4.7,尽管我认为它与它没有任何关系。

So - why does this happen, and how can I fix it? 那么 - 为什么会发生这种情况,我该如何解决?

Put the libs last on the command line: 将libs放在命令行的最后:

g++ test.cpp -o test `pkg-config --libs allegro-5.0`

When linking, the order of the files and libraries matter. 链接时,文件和库的顺序很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM