【发布时间】:2012-01-14 22:47:19
【问题描述】:
一旦我安装了 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)上一切正常。 我应该给你看哪个文件?
【问题讨论】:
标签: gcc linker linker-errors undefined-reference