views:

46

answers:

2

Hi guys, I have a project. I need in shared library of it to use in extensions. I don't want to make copy of this project but with shared-library settings. Are there any way to build it using *.o-files from building project? As I understand, I can write makefile for this.

+1  A: 

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

pajton
+5  A: 

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.

Timo Geusch
+1 I forgot to mention that object files need fpic too.
pajton
@pajton - Guess who's been caught out by this before :).
Timo Geusch