Re: Compiling glib applications



On 09/08/12 14:42, Stef Walter wrote:
On 08/09/2012 02:46 PM, Lanoxx wrote:
But it turns out this is wrong, and the correct way is:

     gcc main.c `pkg-config --cflags glib-2.0` `pkg-config --libs
glib-2.0` -o main --std=c99

The only difference is that the file name is in the front instead of the
end. When I tried the first version, it would compile but give link
errors such as:
main.c:(.text+0x1e1): undefined reference to `g_list_append'. Once I put
the file name at the beginning it worked well.

That's odd. I haven't experienced this at all, even when doing compiling
and linking in one step.

I'm sure someone more knowledgeable than me will pipe in.

I had this years ago when building on Windows. There it used to matter the ordering which you used for linking. On Linux (on the other hand) you could easily just use 1 pkg-config command with both --cflags --libs and it would work.

Tor might have more insight here, but IIRC, it was because symbols had to be resolved hierarchically (i.e. libxml would come before glib because of the symbol dependency chain).

Not sure this is still the case these days, the usual way I would do this is:

  gcc --std=c99 main.c -o main `pkg-config --cflags --libs glib-2.0`

--
Regards,
Martyn

Founder and CEO of Lanedo GmbH.


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