using static libraries

Kristoff Bonne
Mon Nov 29 08:13:00 GMT 2010

Hi Josef,

Thanks for your reply.

Op 29-11-10 00:22, Josef Ahmad schreef:
> Hello there,

> I advised you to put the library inclusions (eg. -lpthread) last in the
 > command line, because the gnu linker satisfies  the reference at
 > these libraries after encountering the C files that call them.

You where correct.

After playing around with all the options a little bit, I got it to 
compile when
- I added -lm, -lc and -logg and -lFLAC (these two are used by libsndfile)
- I put -lrt and -lpthread

> In fact, as you can notice, the errors the linker now gives are related
 > to the libraries, and not to your user code any longer. (while,
 > before issuing the command as I suggested you, the build
 >  stopped even before, because it did not find the library
 > requested to link).

Yep. Indeed.

So what did we learn today?

1/ when doing static linking, the order of the libraries included does 

2/ first compile it using dynamic linking then use "ldd" to see what 
libraries are needed. Then use that information to compile it statically.

Thanks for all the help!

> Let me know,
> J.
Cheerio! Kr. Bonne.

More information about the Gcc-help mailing list