在OS X Yosemite上构建binutils的交叉编译 [英] Building a cross compile of binutils on OS X Yosemite

查看:305
本文介绍了在OS X Yosemite上构建binutils的交叉编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac OS X上构建用于生成MIPS代码的binutils。



我发现这个网站( 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目标,然后按照说明操作。

我从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 =已弃用声明



然后,我配置,并制作bintuils。

问题是,在构建静态库之后,我有一个错误消息,说明存档不是为 x86_64 构建的,那么我有一堆未定义的符号错误。

 忽略文件./../intl/libintl.a,文件是为归档而构建的,而不是被链接的体系结构x86_64):./../intl/libintl.a 

架构x86_64的未定义符号:
__bfd_abort,引用来自:
write.o中的$ fix_new_internal
_size_seg in write.o

使用谷歌搜索找到我需要设置AR(存档) 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:找不到插件'liblto_plugin.so'

再次使用Google搜索找到gcc-ar doesn'不适用于Mac OS X( https://gcc.gnu.org/bugzilla /show_bug.cgi?id=56893 )。

  gcc-ar仅适用于较新的GNU binutils,因为它是唯一支持插件的ar。 
苹果公司的ar不支持插件(尽管可以做;它将是一个不同于GCC支持的GNU BFD
插件界面的插件界面)。

我在 / usr /本地/ Cellar / gcc48 / 4.8.4 / libexec / gcc / x86_64-apple-darwin14.3.0 / 4.8.4 目录来抑制错误信息,但在这种情况下,它看起来像<$ c当我使用 /usr/bin/gcc-ar-4.8 来获得相同的体系结构和未定义的符号时,调用$ c> / usr / ar 错误。

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

解决方案

Mac OS X的静态库生成器不是 ar ,但 libtool -static 。还有另一个关于此的SO帖子 - Mac OS X的静态库链接问题:找不到x86_64体系结构的符号

binutils 具有静态链接的多个库。因此,我用 libtool -static -o 替换了所有 ar rc 命令以获取不会导致错误的静态库。

在这样做的时候,我还必须做两个修改。


  1. 某些库会生成 libtool 脚本来冲突Mac OS X的 libtool ,我不得不重命名脚本。

  2. 有些目标文件不包含符号,我不得不删除这些目标。

然后我可以得到没有任何问题的二进制文件。

I'm trying to build binutils for generating MIPS code on Mac OS X.

I found this site (http://www.theairportwiki.com/index.php/Building_a_cross_compile_of_GCC_for_MIPS_on_OS_X) from How to build GCC 4.8.x on Mac OS X host for MIPS target, and followed the instructions.

I install the gcc-4.8 from brew, and installed source code of binutils and gcc. This is the compilation option setup.

$ 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

Then I configure, and make the bintuils.

The issue is that after building static libraries I have an error message that archive is not built for x86_64, and then I have a bunch of undefined symbol error.

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

Googling to find that I need to setup AR (archive) variable also from https://github.com/tpoechtrager/osxcross/issues/11. I added export AR=/usr/local/bin/gcc-ar-4.8, but I have another error message because gcc-ar-4.8 doesn't work.

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

Googling again to find that gcc-ar doesn't work with Mac OS X (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).

I just created a dumb 'liblto_plugin.so' file in /usr/local/Cellar/gcc48/4.8.4/libexec/gcc/x86_64-apple-darwin14.3.0/4.8.4 directory to suppress the error message, but in this case it looks like that /usr/ar is invoked when I use /usr/bin/gcc-ar-4.8 to get the same architecture and undefined symbols error.

How to solve these issues? How to build cross compiler tools (gcc and binutils) on Mac OS X?

解决方案

The static library generator for Mac OS X is not ar, but libtool -static. There is another SO post about this - Static library link issue with Mac OS X: symbol(s) not found for architecture x86_64.

The binutils has multiple libraries that are linked statically. So I replaced all the ar rc command with libtool -static -o to get the static libraries that do not cause errors.

In doing so, I had to make two modifications also.

  1. Some library generate libtool script to conflict the Mac OS X's libtool, I had to rename the script.
  2. Some object files do not contain symbols, I had to remove the objects.

Then I could get the binaries without any issue.

这篇关于在OS X Yosemite上构建binutils的交叉编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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