views:

37

answers:

2

i have a c program that relies on a second library whose compilation i can control. i want to be able to compile my program into a shared object library without it linking to the second library. in other words i want a single monolithic shared object library at the end. how can i do this?

if i separately compile the second library into a .so and include that as a dependency when compiling my program, i can see that i need that file when i run ldd on the binary.

+2  A: 

You need to compile your second library as a .a (static library) and statically link that into your c program.

Static linking is when object files are linked at compile time and are part of the final binary, the resulting executable can be executed with no dependencies..

Shared libraries (.so) are linked at run time and must be available when you execute the binary that links them.

the gcc flag to link statically is: -static this will automatically search for .a files.

radman
A: 

What radman said above.

http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html

Sanketh I