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.
Timo Geusch Apr 6 2018-10-06T00: 00Z
source share