Making a shared library from existing object files

爱⌒轻易说出口 提交于 2019-12-21 01:11:13

问题


I have a project in my IDE. I need to make a shared library of it to use in extensions. I don't want to make a copy of this project with shared-library settings. Is there any way to build a shared library using the object files (.o) from my already existing project? As I understand, I can write a makefile for this.


回答1:


I assume you're on some sort of Unix and are probably using the GNU toolchain. In that case, to create a proper shared library, you'd need to compile your code using the position-independent code flags (-fpic or -fPIC) before you can create a shared library. Unless your .o files are already compiled with those flags, chances are you won't end up with a working shared lib.

If they already are compiled for position independent code, the usual g++ -shared ... should do the trick.




回答2:


g++ -shared -fPIC -o myshared.so *.o



来源:https://stackoverflow.com/questions/2583770/making-a-shared-library-from-existing-object-files

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