开发者

Making a shared library from existing object files

开发者 https://www.devze.com 2022-12-25 14:30 出处:网络
I have a project in my IDE. I need to make a sha开发者_运维知识库red 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

I have a project in my IDE. I need to make a sha开发者_运维知识库red 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消