一旦我安裝了Ubuntu 11.10,就會出現奇怪的錯誤。我想用我的C程序使用GD,所以我安裝了軟件包「libgd2-xpm-dev」。所有東西都已安裝 - 文件gd.h和libgd.a位於「/ usr/include」和「/ usr/lib」中。所以,我試圖用GD編譯簡單的程序。關於非常簡單的程序的未定義參考
#include <stdio.h>
#include <gd.h>
int main()
{
gdImagePtr im, im_clear;
int black, white;
FILE *out1;
im = gdImageCreate(100, 100);
im_clear = gdImageCreate(100, 100);
white = gdImageColorAllocate(im, 255, 255, 255);
black = gdImageColorAllocate(im, 0, 0, 0);
return 0;
}
$ gcc -lgd gd.c
/tmp/cc6LReuX.o: In function `main':
gd2.c:(.text+0x19): undefined reference to `gdImageCreate'
gd2.c:(.text+0x31): undefined reference to `gdImageCreate'
gd2.c:(.text+0x59): undefined reference to `gdImageColorAllocate'
gd2.c:(.text+0x81): undefined reference to `gdImageColorAllocate'
等等,什麼?好的,我們來檢查一下。
# Let's sure the lib was found.
$ gcc -lgd_something gd.c
/usr/bin/ld: cannot find -lgd_something
# Lets sure we made no mistake with the symbol's name
$ nm /usr/lib/libgd.a
...
00000dc0 T gdImageColorAllocate
...
000003b0 T gdImageCreate
# So, everything should be ok
$ gcc -lgd gd.c
/tmp/cc6LReuX.o: In function `main':
gd2.c:(.text+0x19): undefined reference to `gdImageCreate'
gd2.c:(.text+0x31): undefined reference to `gdImageCreate'
gd2.c:(.text+0x59): undefined reference to `gdImageColorAllocate'
gd2.c:(.text+0x81): undefined reference to `gdImageColorAllocate'
$ echo $LD_LIBRARY_PATH
# Nothing
我不知道該怎麼做。這是gcc中的錯誤還是我做錯了什麼。在我之前的操作系統(Ubuntu 10.04)上,一切運行良好。 我應該爲你展示哪個文件?
的[接頭告訴我它無法解析符號,但他們在那裏?(可能重複http://stackoverflow.com/questions/8382153/linker-tells-me-it-cant-解決 - 符號,但他們在那裏) –