Building a cross compile of binutils on OS X Yosemite

2.7k views Asked by At

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?

1

There are 1 answers

0
prosseek On BEST ANSWER

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.