C Undefined reference with -static ? Packages problem ?

Hi guys.
I want to ask you.

When i compile my program with clang with -static flag i get undefined reference.
But when i compile wiithout -static all work fine.

I installed mysql with pkg install mysql57-server
and i added includes and libs.

Without static flag work, with static no. What i can do ?
 
Tell us more about your program, which libraries you are trying to link with, and what the undefined references are.
 
When i compile my program with clang with -static flag i get undefined reference.
[...]
Without static flag work, with static no. What i can do ?

Typical reason: dynamic shared objects (aka libraries in .so format) can depend on other dynamic shared objects and the dynamic linker will automatically resolve those dependencies.

So, say your program depends on libfoo and this lib itself depends on libbar. For dynamic linking, you only need to say -lfoo because this includes the dependency to libfoo in your program and the dynamic linker will ultimately load both libs.

Static libs on the other hand are nothing more than an archive of object (.o) files, without any further dependency information. To link the static libs correctly in the above example scenario, you'd have to write -lfoo -lbar.
 
Back
Top