Possible to statically link shared object libraries?

这一生的挚爱 提交于 2019-12-13 04:47:13

问题


I'm building a library that needs to be dynamically linked to my project. The output is a .so file, so I think I'm on the right track. I'm concerned by the way it's being linked at compile time - by specifying the location of its makefile and depending on a bunch of macros, which I've never encountered before.

Can I assume that since I'm building a .so library (rather than a .a) that I'm in fact dynamically linking? Or is it possible for .so libs to be statically linked, in which case I need to rip apart the make/config files to better understand what's going on?

Thanks,

Andrew


回答1:


I'm not familiar with internal structure of executables and shared objects, so I could only give some practical hints.

Assuming you use gcc, it should have -shared option when linking object files into library - this way ld (called by gcc) makes shared object instead of executable binary.

gcc -shared -o libabc.so *.o ...

When you link some application with this libabc.so it should link without errors and after that with ldd command you should be able to see libabc.so among its dependencies.

$ ldd app
    ...
    libabc.so => ...............


来源:https://stackoverflow.com/questions/4430645/possible-to-statically-link-shared-object-libraries

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