如何在 Mac OS X 上进行 ARM 交叉编译(错误:无效的列表选项 `r' - 交叉编译错误) [英] How to make ARM cross compilation on Mac OS X (error: invalid listing option `r' - cross compiling error)

查看:35
本文介绍了如何在 Mac OS X 上进行 ARM 交叉编译(错误:无效的列表选项 `r' - 交叉编译错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Mac OS X 上构建一个 gcc 交叉编译器,目标是 arm-elf-eabi.

I'm trying to build a gcc cross compiler on Mac OS X, the target is arm-elf-eabi.

这是我目前所做的:

我尽量不使用 Mac 的 clang/llvm,所以我使用了 brew 的 gcc-4.8.

I tried not to use clang/llvm from Mac, so I used the gcc-4.8 from brew.

brew tap homebrew/versions 
brew install gcc48
brew install binutils

在构建之前,我设置了环境变量:

Before the building, I set the environment variables:

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
export TARGET=arm-elf-eabi

构建 binutils

下载一个 binutils 源代码,然后创建一个构建目录,并且可以毫无问题地构建 binutils:

build binutils

Downloading a binutils source, then creating a build directory, and could build binutils without an issue:

mkdir build-binutils
cd build-binutils
../binutils-2.24/configure --target=$TARGET --prefix=$PREFIX --with-sysroot --enable-64-bit-bfd --disable-shared --disable-werror --disable-nls
make configure-host
make LDFLAGS="-all-static"
sudo make install

构建 gcc

下载 gcc 4.8 源码,并运行构建过程

building gcc

Downloading gcc 4.8 source, and run the build process

mkdir build-gcc
cd build-gcc
../gcc-4.8.3/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers --disable-shared --enable-multilib --with-sysroot --disable-werror
make configure-host
make all-gcc << ERROR
make all-target-libgcc

但是,我在构建时遇到了无效列表选项r'` 错误.

However, I got invalid listing optionr'` error in building.

/usr/local/bin/g++-4.8 -c   -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE  -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -Ibuild -I../../gcc-4.8.3/gcc -I../../gcc-4.8.3/gcc/build -I../../gcc-4.8.3/gcc/../include  -I../../gcc-4.8.3/gcc/../libcpp/include  \
        -o build/genconstants.o ../../gcc-4.8.3/gcc/genconstants.c
Assembler messages:
Fatal error: invalid listing option `r'
make[2]: *** [build/genconstants.o] Error 1
make[1]: *** [all-gcc] Error 2

替代构建过程

我尝试使用 Mac 的默认编译器,配置如下:

Alternative building process

I tried to use default compiler from Mac with the following configuration:

./contrib/download_prerequisites
CFLAGS="-arch i386 -arch x86_64 -Wno-error=deprecated-declarations -Wno-error=unused-variable -Wno-error=unused-function" ../gcc-4.8.3/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c --without-headers --disable-shared --enable-multilib

然后,它与 make all-gcc 一起工作得很好,但我也有与 make all-target-libgcc 不同的错误,所以我会坚持使用 gcc 方法而不是 clang/llvm 方法.

Then, it works fine with make all-gcc, but I also have different error with make all-target-libgcc, so I'll stick to gcc approach instead of clang/llvm approach.

我的猜测是 Apple 的汇编程序 as 对 gcc 给出的参数有问题(因为 clang/llvm 没有问题).

My guess is that the assembler as from Apple has something wrong with parameters that gcc gives (because there's nothing wrong with clang/llvm).

可能有什么问题?如何解决这个问题?

What might be wrong? How to solve this issue?

推荐答案

build-gcc/gcc目录下,存在一个as脚本文件来代替调用/usr/bin/as.当我将 as 重命名为 as_temp 并重新运行时,一切正常.环境变量 AS=/usr/bin/as 似乎没有解决这个问题.

In the directory build-gcc/gcc, there exists an as script file to be invoked instead of the /usr/bin/as. When I renamed as to as_temp, and rerun, everything works fine. The environmental variable AS=/usr/bin/as does not seem to solve this issue.

我需要再做一个修改,应该创建 /opt/cross/arm-elf-eabi/sys-root/usr/include 以防止出现另一条错误消息.

I needed one more modification that /opt/cross/arm-elf-eabi/sys-root/usr/include should be created in order to prevent another error message.

我还发现 这个站点 在 Mac OS X 上的交叉编译中非常有用.

I also found that this site is pretty useful in cross compilation on Mac OS X.

这篇关于如何在 Mac OS X 上进行 ARM 交叉编译(错误:无效的列表选项 `r' - 交叉编译错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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