问题
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