What library would it link against - static or shared object

风流意气都作罢 提交于 2020-01-05 13:51:12

问题


I have a C++ based project(many source files) compiled using gnu make via a makefile. I have an application which links a library, say mylib. Now mylib is owned by some other developer. I see 2 files present in the path where the library binaries are generated namely libmylib.so (shared object) and libmylib.a (static library archive file)

My application makefile has below linker option to link the library mylib

LDFLAGS+=-l:mylib ...

Question is what version of the library mylib would be linked in my application executable

Would the shared object libmylib.so or static version libmylib.a ?

How would it be decided, would there be any other makefile option to govern this?


回答1:


By default on non embedded Linux, you'll get dynamic linkage. If you want to change that, you can specify it in LDFLAGS;

LDFLAGS+= -Wl,--Bstatic -lmylib -Wl,--Bdynamic

(possibly quotes are required) This will switch to static for this lib only, then back to the default dynamic.



来源:https://stackoverflow.com/questions/14731219/what-library-would-it-link-against-static-or-shared-object

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