如何跨ARM编译?

如何为ARM处理器设置GCC以进行交叉编译? 主机将在x86_64(AMD64 – Ubuntu 12.04)上,目标是ARM(Raspberry Pi以及Pandaboard – 将为每个进行单独的编译)?

安装gcc-arm-linux-gnueabibinutils-arm-linux-gnueabi包,然后使用arm-linux-gnueabi-gcc代替gcc进行编译。

你需要小心你的目标系统上有什么样的linux和binutils。 最新的东西是hardfloat,在这种情况下你会做:

 sudo apt-get install gcc-arm-linux-gnueabihf 

这带来了完整的交叉编译环境,包括binutils。

磁盘映像提供程序还必须提供兼容的交叉编译器

这是唯一可靠的方法。

特别是对于RPI,提供的交叉编译器可从以下url获得: https : //github.com/raspberrypi/tools ,可以按照以下说明使用: https : //raspberrypi.stackexchange.com/questions/64273/installing-raspberry- PI-交叉编译器/ 83215#83215

 git clone https://github.com/raspberrypi/tools export PATH="$(pwd)/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}" printf '#include \nint main() { puts("hello world"); }\n' > hello_world.c printf '#include \nint main() { std::cout << "hello world" << std::endl; }\n' > hello_world.cpp arm-linux-gnueabihf-gcc -std=c99 -o hello_world_c hello_world.c arm-linux-gnueabihf-g++ -std=c++11 -o hello_world_cpp hello_world.cpp 

如果您错误地选择了自己的交叉编译器,可能会发生以下情况:

  • 动态链接器的路径错误: https : //stackoverflow.com/questions/31929092/trying-to-run-a-cross-compiled-executable-on-target-device-fails-with-no-such-f / 49993116#49993116
  • 与glibc和您链接的任何其他库的二进制不兼容: https : //stackoverflow.com/questions/11107263/how-compatible-are-different-versions-of-glibc

我最喜欢的替代方案是使用Buildroot构建您自己的映像: https ://stackoverflow.com/questions/47557262/how-to-download-the-torvalds-linux-kernel-master-recompile-it-and-boot-it- wi / 49349237#49349237从源代码构建所有内容并确保一切都兼容。