How to create a shared object file from static library

后端 未结 2 1872
醉梦人生
醉梦人生 2020-12-16 01:25

How to create a shared object file from a static library? I am using Cygwin.

Is the following syntax correct?

gcc -shared -o libexample.so libexample         


        
相关标签:
2条回答
  • 2020-12-16 01:52
    gcc -shared -o libexample.so -Wl,--whole-archive libexample.a
    

    Pay attention that often you'll want the objects combined in your .so to be compiled as PIC, something you don't often want for a static library.

    0 讨论(0)
  • 2020-12-16 02:07

    It might not work but you can always try:

    ar -x libexample.a
    gcc -shared *.o -o libexample.so
    

    If it complains about -fPIC, then it probably won't work.

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