Undefined link to a very simple program

As soon as I installed Ubuntu 11.10, a strange error appears. I want to use GD with my C program, so I installed the package "libgd2-xpm-dev". Everything was installed - the files gd.h and libgd.a are in "/ usr / include" and in "/ usr / lib". So, I tried to compile a simple program using 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'

Wait what? Ok, let's check something out.

# Let 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 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

And I don’t know what to do. Is this a bug in gcc or something is wrong. On my previous os (Ubuntu 10.04) everything works fine. Which file should I show you?

+5
source share
1 answer

Edit:

$ gcc -lgd gd.c

at

$ gcc gd.c -lgd 

(: !)

, -Wall, - , , .

$ gcc -Wall gd.c -lgd 
+5

All Articles