Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

macos - How to make ARM cross compilation on Mac OS X (error: invalid listing option `r' - cross compiling error)

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

This is what I've done so far:

Install gcc and environmental setup

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

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

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

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

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

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Install homebrew, brew cask and then:

brew cask install gcc-arm-embedded

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...