Creating a shared library from existing object files

I have a project in my IDE. I need to make a shared library for use in extensions. I do not want to make a copy of this project with the settings of the shared library. Is there a way to create a shared library using object files (.o) from an existing project? As far as I understand, I can write a makefile for this.

+8
c ++ shared-libraries makefile
Apr 6 '10 at 9:25 am
source share
2 answers

I assume that you are using some kind of Unix and are probably using the GNU toolchain. In this case, to create an appropriate shared library, you will need to compile your code using position-independent code flags (-fpic or -fPIC) before you can create a shared library. If your .o files are already compiled with these flags, most likely you will not get a working shared lib.

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

+13
Apr 6 2018-10-06T00:
source share

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

+7
Apr 6 2018-10-06T00:
source share



All Articles