问题描述
我正在运行 Ubuntu 12:04LTS 并安装了 arm-linux-gnueabi C 和 C++ 编译器.编译后的二进制文件不会在我的目标板上运行.看起来即使我指定了 cpu 和 arch,编译器仍然为错误的 CPU 构建二进制文件.而不是 atm9tdmi 它构建和 7-A.
我做错了什么还是我应该配置什么?谢谢.
~/ArmTest$ arm-linux-gnueabi-g++-4.4 -mcpu=arm9tdmi -march=armv4t -O main.cpp -o CPPTest~/ArmTest$ readelf -A CPPTTest属性部分:aeabi文件属性Tag_CPU_name:7-A"标签_CPU_arch:v7Tag_CPU_arch_profile:应用程序Tag_ARM_ISA_use:是的Tag_THUMB_ISA_use:拇指 2Tag_FP_arch:VFPv3-D16Tag_ABI_PCS_wchar_t:4Tag_ABI_FP_denormal:需要Tag_ABI_FP_exceptions:需要Tag_ABI_FP_number_model:IEEE 754Tag_ABI_align_needed:8 字节Tag_ABI_align_preserved:8 字节,叶 SP 除外Tag_ABI_enum_size: intTag_ABI_HardFP_use:SP 和 DPTag_CPU_unaligned_access: v6Tag_DIV_use:不允许~/ArmTest$ 文件 CPPTTestCPPTest:ELF 32 位 LSB 可执行文件,ARM,版本 1 (SYSV),动态链接(使用共享库),适用于 GNU/Linux 2.6.31,BuildID[sha1]=0xf8e81f7a1bb3ee1200cb3dd1aa5b192ecc6de831,未剥离unname -aLinux 桌面 3.2.0-32-generic-pae #51-Ubuntu SMP Wed Sep 26 21:54:23 UTC 2012 i686 athlon i386 GNU/Linux:~/ArmTest$ arm-linux-gnueabi-g++-4.4 -v使用内置规范.目标:arm-linux-gnueabi配置:../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.7-1ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.错误 --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.4.7 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --program-prefix=arm-linux-gnueabi- --includeir=/usr/arm-linux-gnueabi/include --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-linux-gnueabi --with-headers=/usr/arm-linux-gnueabi/include --with-libs=/usr/arm-linux-gnueabi/lib线程模型:posixgcc 版本 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2):~/ArmTest$ cat main.cpp#include<iostream>使用命名空间标准;诠释主要(){cout<
您的编译器支持 armv4t,问题是您的链接器必须将您的目标文件与 libc、crt.o 等其他文件链接以创建可执行文件.但是,在您的工具链中,所有这些文件都已针对 7-A 编译,因此结果可执行文件最终也是一个.这是 ubuntu 跨工具链的问题,默认是 armv7a.
如果您只编译源文件,您会看到编译器输出正确的目标文件类型.
$ arm-linux-gnueabi-g++-4.4 -mcpu=arm9tdmi -march=armv4t -O -c main.cpp -o CPPTest
$ readelf -A CPPTTest属性部分:aeabi文件属性Tag_CPU_name: "ARM9TDMI"标签_CPU_arch:v4TTag_ARM_ISA_use:是的Tag_THUMB_ISA_use: Thumb-1Tag_FP_arch:VFPv3-D16Tag_ABI_PCS_wchar_t:4Tag_ABI_FP_denormal:需要Tag_ABI_FP_exceptions:需要Tag_ABI_FP_number_model:IEEE 754Tag_ABI_align_needed:8 字节Tag_ABI_align_preserved:8 字节,叶 SP 除外Tag_ABI_enum_size: intTag_ABI_HardFP_use:SP 和 DPTag_ABI_optimization_goals:首选速度Tag_DIV_use:不允许
因此,工具链不仅仅是一个编译器,它的每个组件都需要配合.
I'm running Ubuntu 12:04LTS and installed arm-linux-gnueabi C and C++ compiler. The compiled binary won't run on my target board. It looks like even if I specify the cpu and arch, the compiler still builds a binary for the wrong CPU. Instead of atm9tdmi it build and 7-A.
Am I doing something wrong or is there something I should have configured? Thanks.
~/ArmTest$ arm-linux-gnueabi-g++-4.4 -mcpu=arm9tdmi -march=armv4t -O main.cpp -o CPPTest
~/ArmTest$ readelf -A CPPTest
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
Tag_CPU_arch_profile: Application
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: VFPv3-D16
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_ABI_HardFP_use: SP and DP
Tag_CPU_unaligned_access: v6
Tag_DIV_use: Not allowed
~/ArmTest$ file CPPTest
CPPTest: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0xf8e81f7a1bb3ee1200cb3dd1aa5b192ecc6de831, not stripped
uname -a
Linux Desktop 3.2.0-32-generic-pae #51-Ubuntu SMP Wed Sep 26 21:54:23 UTC 2012 i686 athlon i386 GNU/Linux
:~/ArmTest$ arm-linux-gnueabi-g++-4.4 -v
Using built-in specs.
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.7-1ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.4.7 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-linux-gnueabi --with-headers=/usr/arm-linux-gnueabi/include --with-libs=/usr/arm-linux-gnueabi/lib
Thread model: posix
gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2)
:~/ArmTest$ cat main.cpp
#include<iostream>
using namespace std;
int main(){
cout<<"Hello World"<<endl;
return 0;
}
Your compiler supports armv4t, problem is your linker has to link your object file with other files like libc, crt.o to create an executable. However in your toolchain all those files have been compiled for 7-A, thus result executable ends up being one as well. This is a problem with ubuntu cross toolchains, they are armv7a by default.
If you just compile your source file, you'll see that compiler outputs right object file type.
$ readelf -A CPPTest
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "ARM9TDMI"
Tag_CPU_arch: v4T
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-1
Tag_FP_arch: VFPv3-D16
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_ABI_HardFP_use: SP and DP
Tag_ABI_optimization_goals: Prefer Speed
Tag_DIV_use: Not allowed
So a toolchain is more than a compiler and every component of it needs to play along.
这篇关于为什么arm-linux-gnueabi-g++-4.4总是建一个“7-A"?二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!