创建静态 Mac OS X C 构建

标签 c macos gcc static

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

gcc -o test Main.c -static

我得到:

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

最佳答案

Mac OS X 的 gcc 不支持它:

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

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.

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

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)将是动态的,因此程序将是动态可执行文件。

关于创建静态 Mac OS X C 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5259249/

相关文章:

c - pthreads/等待(&状态)

objective-c - Swift如何编写plist文件并更改值?

c++ - 如何在宏定义中连接 __func__ 和 __LINE__

c - gcc-10.0.1 特定的段错误

c - 当您使用 GCC 编译 C 代码时,堆栈是否以错误的方式增长

c++ - 基于变量值静态定义数组 C/C++

c - 后增量和预增量运算符

python - 我的 mac 终端无法运行 python 函数

c - 为什么 strtok_r 总是找到模式 "."?

cocoa - OS X 10.6 Snow Leopard 中的 NSTask 问题