我使用以下方法在Ubuntu系统上安装了交叉编译工具:
sudo apt-get install gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi
然后我制作了一个简单的.c文件,可以正常编译,但是当gcc运行汇编程序阶段时,由于未知原因调用了“ as”命令,而不是适当的“ arm-linux-gnueabi-as”命令并进行了结果编译失败并显示以下错误:
arm-linux-gnueabi-gcc -v test.c
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/6/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armel-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armel-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armel-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 6.3.0 20170406 (Ubuntu/Linaro 6.3.0-12ubuntu2)
COLLECT_GCC_OPTIONS='-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/6/cc1 -quiet -v -imultiarch arm-linux-gnueabi test.c -quiet -dumpbase test.c -march=armv5t -mfloat-abi=soft -mtls-dialect=gnu -auxbase test -version -fstack-protector-strong -Wformat -Wformat-security -o /tmp/cccUVSll.s
GNU C11 (Ubuntu/Linaro 6.3.0-12ubuntu2) version 6.3.0 20170406 (arm-linux-gnueabi)
compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/lib/gcc-cross/arm-linux-gnueabi/6/../../../../arm-linux-gnueabi/include"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-cross/arm-linux-gnueabi/6/include
/usr/lib/gcc-cross/arm-linux-gnueabi/6/include-fixed
/usr/include
End of search list.
GNU C11 (Ubuntu/Linaro 6.3.0-12ubuntu2) version 6.3.0 20170406 (arm-linux-gnueabi)
compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 50226affb1339dba25cfdfb2ad79e687
COLLECT_GCC_OPTIONS='-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
as -v -march=armv5t -mfloat-abi=soft -meabi=5 -o /tmp/cczGBXSH.o /tmp/cccUVSll.s
GNU assembler version 2.28 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.28
Assembler messages:
Fatal error: invalid -march= option: `armv5t'
如您所见,它失败了,因为它调用了错误的命令- as ,该命令仅了解 x86_64-linux-gnu 目标,并且无法识别 armv5t 架构选项。
如何强制gcc工具链使用正确的跨平台汇编器/链接器生成二进制文件,而不是“ as”,“ ld”等? 我的环境中是否有引起这种行为的东西?
P.S。在我大学的机器上,安装相同的工具链可以正常工作,但是他有Ubuntu 16.04,而我的是17.04 .. GCC为汇编程序执行以下命令:
/ usr / lib / gcc-cross / arm-linux-gnueabi / 5 /../../../../ arm-linux-gnueabi / bin / as -v -march = armv5t -mfloat-abi = soft -meabi = 5 -o /tmp/ccXru9b3.o /tmp/ccUwNPuq.s
如您所见,它需要正确的汇编程序,一切正常..但是在我的系统上不是。