【问题标题】:Cross-compiling binutils on OS X在 OS X 上交叉编译 binutils
【发布时间】:2013-12-02 20:41:43
【问题描述】:

我正在尝试在 OS X Mavericks 上创建 Linux Arm 工具链。我在/usr/local/gcc-4.8.1-for-linux64/bin/ 中有 GCC 4.8.1 二进制文件,这是我用来为 binutils 生成配置脚本的命令:

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

在运行make all 时,我得到了这个错误:

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

错误的原因是什么,我该如何解决?


更新 1

更新binutils到2.24,错误改成

[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  ]                                    ^

没有设置自定义编译器/链接器标志。

【问题讨论】:

  • 看起来您已经解决了 binutils 问题,并开始着手构建 eglibc。由于我从未使用过 eglibc,因此我无法帮助您。 ELLCC 使用 musl 作为其标准 C 库。
  • 非常感谢您的建议@RichardPennington 澄清一下,您怎么知道使用了eglibc?我一直在 crosstool-ng 中选择 glibc。
  • 这是一个猜测。我用谷歌搜索了 rpc_scan.c,并提到了与 eglibc 相关的内容。我很容易就错了。重要的是你已经通过了 binutils。

标签: gcc cross-compiling toolchain binutils


【解决方案1】:

使用更高版本的 binutils。这种事情已经在多个地方得到修复。 2.24 版刚刚发布。

更高版本的 binutils 中的修复如下所示:

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

我假设您 Mac 上的“gcc”确实是“clang”。出于这个原因,当我开始自己编译 ELLCC 时,我不得不在基于 clang 的 ELLCC cross tool project 中更新 binutils。

【讨论】:

  • 我用的是crosstool-ng,而binutil的最新版本是2.23
  • 我验证你是用clang编译的。这是一个铿锵的错误信息。
  • 抱歉,crosstool-ng 是使用 binutils 2.22 的人。将我机器上的 binutils 更新到 2.24,出现上述新错误。
【解决方案2】:

我有更新 1 的答案:

这些类型会干扰 OSX 中内置的类型。您需要将此补丁应用到 glibc 源代码中的 types.h

--- 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>

我使用的是 eglibc,所以我的类型位于此处:

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

关于整个过程的更多信息可以在我的blog post 上找到。

干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    相关资源
    最近更新 更多