Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can you please tell me how can I resolve this 'undefined reference' error when linking on Ubuntu 10.10

conftest.c:(.text+0x4): undefined reference to `glib_major_version'

conftest.c:(.text+0xd): undefined reference to `glib_minor_version'

conftest.c:(.text+0x16): undefined reference to `glib_micro_version'

collect2: ld returned 1 exit status

I have added 'export LD_LIBRARY_PATH=/usr/lib:/lib:$LD_LIBRARY_PATH' to my .bashrc.

$ ls -la libgl*.*

lrwxrwxrwx 1 root root 23 2010-12-17 18:29 libglib-2.0.so.0 -> libglib-2.0.so.0.2600.0

-rw-r--r-- 1 root root 842208 2010-09-27 16:16 libglib-2.0.so.0.2600.0

/lib $ pwd

/lib

But that does not solve the problem. What should I do?

share|improve this question
    
Did you add -lglib to your linker options, e.g. gcc -lglib or ld -lglib or LDFLAGS=-lglib? –  Mikel Feb 2 '11 at 20:43
    
Is this your own code, or someone else's? Does it have a ./configure script? You need to show us what leads up to the error, e.g. what command you are running. –  Mikel Feb 2 '11 at 20:55

1 Answer 1

up vote 0 down vote accepted

What command are you running to compile it?

Are there any other errors leading up to this error?


I have the same version of the file as you, and it has those symbols.

$ ls -l libglib*
lrwxrwxrwx 1 root root     23 2010-12-05 06:03 libglib-2.0.so.0 -> libglib-2.0.so.0.2600.0
-rw-r--r-- 1 root root 842208 2010-09-28 09:16 libglib-2.0.so.0.2600.0
$ nm -D libglib-2.0.so.0.2600.0 | grep version
00073730 T glib_check_version
000c849c R glib_major_version
000c84a4 R glib_micro_version
000c84a0 R glib_minor_version

Are you compiling your own program? Perhaps you just need to tell the linker to link in glib by adding the -lglib-2.0 option.

If you are running
gcc -o conftest conftest.c, you should do
gcc -o conftest -lglib-2.0 conftest.c instead.

Or you can add -lglib-2.0 to LDFLAGS.


Are you compiling someone else's program? It might be using pkgconfig. There might be some stuff in /usr/local that is confusing things.

Did you install any other programs or libraries yourself? Perhaps something that installed itself in /usr/local/lib?

What does cat /usr/lib/pkgconfig/glib* say?
What does cat /usr/local/lib/pkgconfig/glib* say?

You might need to change the value of LD_LIBRARY_PATH to include /usr/local/lib, or perhaps change PKG_CONFIG_PATH, or add some options to ./configure.

The answer depends on what you are doing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.