我正在尝试在 Mac OS X 上构建 gcc 交叉编译器,目标是 arm-elf-eabi
。
这是我到目前为止所做的:
安装 gcc 和环境设置
我尝试不使用Mac上的clang/llvm,所以我使用了brew中的gcc-4.8。
brew tap homebrew/versions
brew install gcc48
brew install binutils
在构建之前,我设置了环境变量:
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:
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 4.8 源代码,并运行构建过程
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'` 错误。
/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 上的默认编译器并进行以下配置:
./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 方法。
我的猜测是 Apple 的汇编器 as
对 gcc 提供的参数有问题(因为 clang/llvm 没有任何问题)。
可能出了什么问题?如何解决这个问题?
最佳答案
关于macos - 如何在Mac OS X上进行ARM交叉编译(错误: invalid listing option `r' - cross compiling error),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26197735/