Cross-compiling binutils on OS X

3.1k views Asked by At

I am trying to create a Linux Arm toolchain on OS X Mavericks. I have GCC 4.8.1 binaries in /usr/local/gcc-4.8.1-for-linux64/bin/, and this is the command I use to generate the configure script for binutils:

$ ../binutils-2.23.2/configure --target=arm-unknown-linux --prefix=$PREFIX --bindir=/usr/local/gcc-4.8.1-for-linux64/bin/

When running make all, I got this error:

gcc -DHAVE_CONFIG_H -I. -I../../binutils-2.23.2/binutils  -I. -I../../binutils-2.23.2/binutils -I../bfd -I../../binutils-2.23.2/binutils/../bfd -I../../binutils-2.23.2/binutils/../include -I./../intl -DLOCALEDIR="\"/usr/local/arm/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT readelf.o -MD -MP -MF .deps/readelf.Tpo -c -o readelf.o ../../binutils-2.23.2/binutils/readelf.c
../../binutils-2.23.2/binutils/readelf.c:9046:20: error: adding 'int' to a
      string does not append to the string [-Werror,-Wstring-plus-int]
    fputs ("     " + n, stdout);
           ~~~~~~~~^~~
../../binutils-2.23.2/binutils/readelf.c:9046:20: note: use array indexing to
      silence this warning
    fputs ("     " + n, stdout);
                   ^
           &       [  ]
1 error generated.
make[4]: *** [readelf.o] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-binutils] Error 2
make: *** [all] Error 2

What is the cause of the error and how can I resolve it?


Update 1

Updated binutils to 2.24, the error has changed to

[ALL  ]    x86_64-build_apple-darwin13.0.0-gcc   -D_RPC_THREAD_SAFE_ -D_GNU_SOURCE -DIS_IN_build -include /Volumes/CrosstoolCompile/arm-unknown-linux-gnueabi/build/build-libc-startfiles/config.h rpc_sample.c         -o /Volumes/CrosstoolCompile/arm-unknown-linux-gnueabi/build/build-libc-startfiles/sunrpc/cross-rpc_sample.o -MMD -MP -MF /Volumes/CrosstoolCompile/arm-unknown-linux-gnueabi/build/build-libc-startfiles/sunrpc/cross-rpc_sample.o.dt -MT /Volumes/CrosstoolCompile/arm-unknown-linux-gnueabi/build/build-libc-startfiles/sunrpc/cross-rpc_sample.o -c
[ERROR]    rpc_scan.c:40:10: fatal error: 'libintl.h' file not found
[ALL  ]    #include <libintl.h>
[ALL  ]             ^
[ERROR]    rpc_main.c:41:10: fatal error: 'libintl.h' file not found
[ALL  ]    #include <libintl.h>
[ALL  ]             ^
[ALL  ]    In file included from rpc_clntout.c:34:
[ERROR]    ./rpc/types.h:73:9: error: unknown type name '__u_char'; did you mean 'u_char'?
[ALL  ]    typedef __u_char u_char;
[ALL  ]            ^~~~~~~~
[ALL  ]            u_char
[ALL  ]    /usr/include/sys/types.h:84:24: note: 'u_char' declared here
[ALL  ]    typedef unsigned char           u_char;
[ALL  ]                                    ^

No custom compiler / linker flags set.

2

There are 2 answers

3
Richard Pennington On BEST ANSWER

Use a later version of binutils. This sort of thing has been fixed in multiple places. Version 2.24 just came out.

The fix in later versions of binutils looks like this:

fputs (&" "[n], stdout);

I assume "gcc" on your Mac is really "clang". I had to update binutils in my clang based ELLCC cross tool project for just this reason when I started compiling ELLCC with itself.

0
jaredwolff On

I have an answer for Update 1:

These types are interfering with the ones that are built into OSX. You need to apply this patch to the types.h in your glibc source.

--- types.h 2014-02-06 17:40:13.000000000 -0800
+++ types_new.h 2014-02-06 17:38:22.000000000 -0800
@@ -69,6 +69,9 @@
 #include <sys/types.h>
 #endif

+/* The system headers on Mac OS X conflict with these typedefs */
+#ifndef __APPLE__
+# error Error: should not be here if compiling under OSX.
 #ifndef __u_char_defined
 typedef __u_char u_char;
 typedef __u_short u_short;
@@ -84,6 +87,7 @@
 typedef __caddr_t caddr_t;
 # define __daddr_t_defined
 #endif
+#endif

 #include <sys/time.h>
 #include <sys/param.h>

I was using eglibc so my types was located here:

/Volumes/{your case sensitive image}/.build/src/eglibc-2_17/sunrpc/rpc

More info can be found on my blog post about this whole process.

Cheers!