创建静态 Mac OS X C 构建 [英] Creating static Mac OS X C build

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

问题描述

如何在 Mac OS X 上创建 .c 文件的静态版本?当我尝试:

How can i create a static build of a .c file on Mac OS X ? When i try:

gcc -o test Main.c -static

我明白了:

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

推荐答案

Mac OS X 的 gcc 不支持:

It is not supported in Mac OS X's gcc:

http://discussions.apple.com/message.jspa?messageID=11053384

也许是-static"flag flat out 不适用于 MacOS X.并非 gcc 的所有功能都在 MacOS X 上实现.Apple 甚至不会在未来版本的操作系统中使用 gcc.

Perhaps that "-static" flag flat out won't work on MacOS X. Not all features of gcc are implemented on MacOS X. Apple won't even be using gcc in future versions of the OS.

我不知道如何使用-static"进行链接.我想不出有什么理由在 MacOSX 上这样做.如果我知道你为什么要使用-static"我可能对这个问题更感兴趣.现在,我只是不明白.通过寻求帮助,您实际上是在寻求项目的合作者——即使只有 10 分钟.你需要让我感兴趣.

I don't know how to link using "-static". I can't think of any reason to do so on MacOSX. If I knew why you wanted to use "-static" I might be more interested in the problem. Right now, I just don't get it. By asking for help, you are essentially asking for collaborators on the project - even if it is only for 10 minutes. You need to get me interested.

http://developer.apple.com/library/mac/#qa/qa2001/qa1118.html

Mac OS X 不支持用户二进制文件的静态链接.将用户二进制文件绑定到 Mac OS X 库和接口的内部实现会限制我们更新和增强 Mac OS X 的能力.相反,支持动态链接(链接例如,自动针对 crt1.o 而不是查找 crt0.o).

Static linking of user binaries is not supported on Mac OS X. Tying user binaries to the internal implementation of Mac OS X libraries and interfaces would limit our ability to update and enhance Mac OS X. Instead, dynamic linking is supported (linking against crt1.o automatically instead of looking for crt0.o, for example).

我们强烈建议您非常仔细地考虑静态链接的局限性,并考虑您的客户及其需求,以及您需要提供的长期支持.

We strongly recommend that you consider the limitations of statically linking very carefully, and consider your customer and their needs, plus the long-term support you will need to provide.

更新:被禁止的是静态二进制文件.但是您仍然可以编译一些静态库并将其与另一个程序一起使用.程序将与您的库静态链接,但其他库(如 libc)将是动态的,因此程序将是动态可执行文件.

Update: The prohibited is a static binary. But you still can compile some static library and use it with you another program. Program will be linked statically with your library, but other libraries like libc will be dynamic, so program will be a dynamic executable.

这篇关于创建静态 Mac OS X C 构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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