How to create a shared object file from static library

佐手、 提交于 2019-12-30 03:04:04

问题


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.a

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6263780/how-to-create-a-shared-object-file-from-static-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!