incorporate .so into another .so without dependency?

三世轮回 提交于 2019-12-24 01:41: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.


回答1:


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.




回答2:


What radman said above.

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



来源:https://stackoverflow.com/questions/3571300/incorporate-so-into-another-so-without-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!