问题描述
假设我在Mac上安装了一个名为somelib.a的第三方库,它运行着安装了Xcode 4.4的Mountain Lion。我想要一个名为somelib.dylib的动态库。一个合适的Linux命令将是: g ++ -fpic -shared -Wl,-whole-archive somelib.a -Wl, no-whole-archive -o somelib.so
其中-whole-archive和-no-whole-存档传递给链接器。
当我做相当于Mac的时候:
g ++ -fpic -shared -Wl,-whole-archive somelib。 a -Wl,-no-whole-archive -o somelib.dylib
ld失败并显示错误:
ld:未知选项:-whole-archive
似乎OSX上的ld与GNU ld不同。如何修改上述命令,以便获得所需的结果?
提前谢谢!
我发现我的问题的解决方案:
g ++ -fpic -shared - Wl,-all_load somelib.a -Wl,-noall_load -o somelib.dylib
所需的参数是-all_load和-noall_load。
Suppose I have a third party library called somelib.a on a Mac running Mountain Lion with Xcode 4.4 installed. I want to get a dynamic library out of it called somelib.dylib. An appropriate Linux command would be:
g++ -fpic -shared -Wl,-whole-archive somelib.a -Wl,-no-whole-archive -o somelib.so
where -whole-archive and -no-whole-archive are passed to the linker.When I do the equivalent for Mac:
g++ -fpic -shared -Wl,-whole-archive somelib.a -Wl,-no-whole-archive -o somelib.dylib
ld fails with an error:
ld: unknown option: -whole-archive
It seems that the ld on OSX is different from GNU ld. How do I have to modify above command so I will get the desired result?
Thank you in advance!
I found out the solution to my problem:
g++ -fpic -shared -Wl,-all_load somelib.a -Wl,-noall_load -o somelib.dylib
The required arguments are -all_load and -noall_load.
这篇关于OSX:如何将静态库转换为动态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!