macos - 无法让 GCC 的 -static-libgcc 在 Mac OS X 上与 DYLIB 库一起使用

标签 macos gcc compiler-construction ffmpeg shared-libraries

我已将 GCC 4.6.3 安装到 Mac 系统上的非系统路径中,并且运行良好。但是,GCC 希望对我编译的所有二进制文件使用 libgcc 中的代码,并且运行 otool -L 显示这些编译的程序在 GCC 的安装路径中查找 libgcc_s.1.dylib。我可以通过传递 -static-libgcc 来覆盖它,它只是将所需的内容编译到二进制文件中,这很好。问题是这似乎只适用于可执行文件,而不适用于共享库。如果我使用 GCC 编译一些我想在我的程序之一中使用的第三方库作为 .dylib,这些库仍然会在本地 GCC 安装路径中查找 libgcc_s.1.dylib,即使我指定 -static -libgcc! 不用说,这是一个问题,因为不能保证这些库在其他系统上运行时会找到 libgcc。

我用 ffmpeg 尝试过这个。如果我查看 config.log,肯定会使用 -static-libgcc。 GCC 只是没有将 libgcc 与生成的 dylib 静态链接。我什至尝试了 -nostdlib、-nostartfiles 和 -nodefaultlibs 选项,但它们被忽略了。我再次检查了 config.log,它们肯定在那里!

最佳答案

我相信这与跨共享库边界抛出异常有关。这个page说:

There are several situations in which an application should use the shared libgcc instead of the static version. The most common of these is when the application wishes to throw and catch exceptions across different shared libraries. In that case, each of the libraries as well as the application itself should use the shared libgcc.

Therefore, the G++ and GCJ drivers automatically add -shared-libgcc whenever you build a shared library or a main executable, because C++ and Java programs typically use exceptions, so this is the right thing to do.

该部分的其余部分提供了一个可能的解决方法(看起来),即使用 GCC 驱动程序链接您的共享库,但是如果静态链接库抛出异常,您可能可能遇到分段违规。

关于macos - 无法让 GCC 的 -static-libgcc 在 Mac OS X 上与 DYLIB 库一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9924632/

相关文章:

objective-c - 如何检查最前面的应用程序是否全屏?

xcode - 在较早的osx版本中,从xcassets加载带有imageNamed的NSImage会崩溃

cocoa - 在我的应用程序主菜单中设置项目标题?

c++ - 在没有 AVX 的情况下编译 boost

linux - 无法使用 Cygwin 访问 sys/socket.h

c - 以编程方式生成 C Win32 DLL

ruby - 通过 macports 安装了 fxruby,现在 ruby​​gems 坏了

c - Mex 在 Linux 中编译 C 代码时生成错误//

c++ - 添加 "extern C"作为符号的编译器选项?

javascript - PEG.js-如果表达式不匹配则抛出错误