Re: Glib linking error: undefined reference to ...

On 17 February 2012 00:20, Christian Arnold <chrarnold web de> wrote:

I am not sure if this is the correct way of asking my question, but I nevertheless hope someone can help me... I just tried to solve the problem for 4 hours, and I am extremely frustrated right now... I have the following issue:

I installed Ubuntu 11.10 and some libraries and packages afterwards. I then installed glib 2.30. Everything went fine, I got no errors when doing ./configure, make, or make install. However, when I try to compile a test file in C, I can compile without errors, but I get the following  errors:

glibTest.c:24: undefined reference to `g_timer_new'
glibTest.c:32: undefined reference to `g_random_double'
glibTest.c:36: undefined reference to `g_timer_stop'
glibTest.c:55: undefined reference to `g_str_hash'

I compile with:
"gcc `pkg-config --cflags --libs glib-2.0`  -g3 -O2 -std=c99 -Wall -pedantic glibTest.c -o glibTest

pkg-config --cflags --libs glib-2.0 gives me:
-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include  -L/usr/local/lib -lglib-2.0

This all worked on my old laptop with Ubuntu 10.04, and I have no idea what the issue is. I tried to install glib 2.28 and the newest 2.31 version, with the same error messages. I am no real expert, so please try to help me and let me know as precisely as possible how I can address the issue, I would greatly appreciate it.

Could it be possible that you try to use the static version of glib and, because you pass it 1st on the command line, the symbols you use are not there in the final exe? Can you try the command like:
gcc -g3 -O2 -std=c99 -Wall -pedantic glibTest.c -o glibTest `pkg-config --cflags --libs glib-2.0`


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]