Mac上的静态链接库 [英] statically linked libraries on mac

查看:94
本文介绍了Mac上的静态链接库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是不明白.

我相信gcc在调用gcc驱动程序时会自动链接libc.a.

I'm to believe that gcc automatically links libc.a when invoking the gcc driver.

但是,出于好奇,我想使用 -static 静态链接libc.a,但是我明白了;

However, out of curiosity I wanted to link libc.a statically using -static, but I get;

ld: library not found for -lcrt0.o
collect2: ld returned 1 exit status

我只是不明白?还有, crt0 是什么?

I just don't understand? Also, whats crt0?

我还阅读了从不静态链接libc.a的帖子;为什么?从我读过的内容(当然我只是一个本科生)来看,我看不到静态链接的弊端.

I've also read posts saying to never statically link libc.a ; why? From what I've read (admittedly I'm just an undergrad), I don't see the drawbacks in linking statically..

我阅读了这篇帖子,该帖子告诉我添加 -lc 似乎可以正确编译,但这是静态链接还是只是添加了libc.dylib?

I read this post which told me to add -lc which seems to compile correctly, but is this statically linking or just adding libc.dylib ?

此外,每当我使用 -static 标志时,我都会收到从 ld 返回的相同错误.我听不懂我正在研究的文本显示了使用Unix环境的示例,并且由于OS X是基于Unix的,为什么我的Mac会有这么多困难?

Additionally, anytime I use -static flag, I get the same error returned from ld. I don't understand? The text I'm working through shows examples using a Unix environment, and since OS X is Unix-based, why am I having so many difficulties with my Mac?

谢谢,扎克

推荐答案

这是Apple关于库和开发应如何工作的决定之一.他们通过使它变得尽可能困难来阻止您构建静态二进制文件.

This is one of Apple's decisions about how libraries and development should work. They dissuade you from building static binaries by making it as difficult as possible.

http://上有一些弱项解释developer.apple.com/,有用的提示是:

>     If your project absolutely must create a statically linked binary, 
> you can get the Csu (C startup) module from [Darwin][2] and try
> building crt0.o for yourself. Obviously, we won't support such an
> endeavor.

如果您觉得自己在上游游泳,请习惯一下-因为使用应用程序沙箱,签名,更改模型等操作将不会很容易.

If you feel like you're swimming upstream, get used to it - because it won't get any easier with app sandboxing, signing, dyld changes, etc etc.

从好的方面来说,现在尝试在OSX上做unix东西是很危险的.

On the plus side, trying to do unix stuff on OSX is edgy and dangerous now.

几个有用的链接:

http://reverse.put.as/2013/03/20/如何编译gdb-in-mountain-lion-updated/ http://www.osxbook.com/

这篇关于Mac上的静态链接库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆