在 OS X Yosemite 上构建 binutils 的交叉编译

2024-01-07

我正在尝试构建 binutils 以在 Mac OS X 上生成 MIPS 代码。

我找到了这个网站(http://www.theairportwiki.com/index.php/Building_a_cross_compile_of_GCC_for_MIPS_on_OS_X http://www.theairportwiki.com/index.php/Building_a_cross_compile_of_GCC_for_MIPS_on_OS_X) from 如何在 Mac OS X 主机上为 MIPS 目标构建 GCC 4.8.x https://stackoverflow.com/questions/22776307/how-to-build-gcc-4-8-x-on-mac-os-x-host-for-mips-target,并按照说明进行操作。

我从brew安装了gcc-4.8,并安装了binutils和gcc的源代码。这是编译选项设置。

$ export CC=/usr/local/bin/gcc-4.8
$ export CXX=/usr/local/bin/g++-4.8
$ export CPP=/usr/local/bin/cpp-4.8
$ export LD=/usr/local/bin/gcc-4.8
$ export PREFIX=/opt/cross/gcc-mips
$ export CFLAGS=-Wno-error=deprecated-declarations

然后我配置并制作 binutils。

问题是,在构建静态库后,我收到一条错误消息,指出归档不是为构建的x86_64,然后我有一堆未定义的符号错误。

ignoring file ./../intl/libintl.a, file was built for archive which is not the architecture being linked (x86_64): ./../intl/libintl.a

Undefined symbols for architecture x86_64:
  "__bfd_abort", referenced from:
      _fix_new_internal in write.o
      _size_seg in write.o

谷歌搜索发现我也需要设置 AR(存档)变量https://github.com/tpoechtrager/osxcross/issues/11 https://github.com/tpoechtrager/osxcross/issues/11。我添加了export AR=/usr/local/bin/gcc-ar-4.8,但我有另一个错误消息,因为 gcc-ar-4.8 不起作用。

/usr/local/bin/gcc-ar-4.8 
/usr/local/bin/gcc-ar-4.8: Cannot find plugin 'liblto_plugin.so'

再次谷歌搜索发现 gcc-ar 不适用于 Mac OS X (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56893 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56893).

gcc-ar is for use with newer GNU binutils only as that is the only ar which supports plugins.  
Apple's ar does not support plugins (though it could be made to; it will be a different plugin interface than the GNU BFD 
plugin interface which GCC supports right now).

我刚刚创建了一个愚蠢的“liblto_plugin.so”文件/usr/local/Cellar/gcc48/4.8.4/libexec/gcc/x86_64-apple-darwin14.3.0/4.8.4目录以抑制错误消息,但在本例中它看起来像这样/usr/ar当我使用时被调用/usr/bin/gcc-ar-4.8获得相同的体系结构和未定义的符号错误。

如何解决这些问题?如何在 Mac OS X 上构建交叉编译工具(gcc 和 binutils)?


Mac OS X 的静态库生成器不是ar, but libtool -static。还有另一篇关于此的帖子 -Mac OS X 的静态库链接问题:未找到架构 x86_64 的符号 https://stackoverflow.com/questions/30948807/static-library-link-issue-with-mac-os-x-symbols-not-found-for-architecture-x8.

The binutils有多个静态链接的库。所以我更换了所有ar rc命令与libtool -static -o获取不会导致错误的静态库。

为此,我还必须进行两项修改。

  1. 一些库生成libtool与 Mac OS X 冲突的脚本libtool,我不得不重命名脚本。
  2. 有些对象文件不包含符号,我必须删除这些对象。

然后我就可以毫无问题地获取二进制文件。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 OS X Yosemite 上构建 binutils 的交叉编译 的相关文章

随机推荐