OSX:如何将静态库转换为动态库?

编程入门 行业动态 更新时间:2024-10-22 23:48:24
本文介绍了OSX:如何将静态库转换为动态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 假设我在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:如何将静态库转换为动态库?

本文发布于:2023-11-01 12:33:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   静态   动态   OSX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!