Making a shared library from existing object files

前端 未结 2 537
慢半拍i
慢半拍i 2021-02-09 03:25

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 w

相关标签:
2条回答
  • 2021-02-09 04:07

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

    0 讨论(0)
  • 2021-02-09 04:14

    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.

    0 讨论(0)
提交回复
热议问题