incorporate .so into another .so without dependenc

2019-07-16 04:15发布

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条回答
甜甜的少女心
3楼-- · 2019-07-16 04:23

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.

查看更多
登录 后发表回答