简体   繁体   English

如何交叉编译ARM的自动工具项目?

[英]How to cross-compile a autotools project for ARM?

I am looking to cross-compile an existing library which uses GNU autotools build system. 我正在寻找使用GNU autotools构建系统交叉编译现有库的方法。 I have a Linaro arm-gcc toolchain installed in my host machine and I am able to compile small programs directly using arm-gcc. 我在主机上安装了Linaro arm-gcc工具链,并且能够直接使用arm-gcc编译小程序。

  • Host machine: Ubuntu 12.04 Intel x64 主机: Ubuntu 12.04 Intel x64
  • Target machine: Ubuntu 14.04 ARM 32-bit (a board similar to Raspberry-Pi) 目标机器: Ubuntu 14.04 ARM 32位(类似于Raspberry-Pi的主板)

I have a library source code which has configure.ac and Makefile.am files for it. 我有一个库源代码,其中包含configure.ac和Makefile.am文件。 I want to compile this code on host machine and generate ARM binaries which can be copied over to the target platform. 我想在主机上编译此代码,并生成可以复制到目标平台的ARM二进制文件。

What is the canonical way to do this? 规范的做法是什么?

For specifics, I am looking for something that would work for a "Hello World" application/library in C cross-compiled using arm-linux-gnueabi-gcc and autotools. 具体来说,我正在寻找适用于使用arm-linux-gnueabi-gcc和autotools交叉编译的C语言中的“ Hello World”应用程序/库的东西。

--build=`./config.guess` --host=arm-linux-gnueabi

might be sufficient, as it will look for a corresponding ARM toolchain. 可能就足够了,因为它将寻找相应的ARM工具链。 Otherwise, try adding: CC="arm-linux-gnueabi-gcc" 否则,请尝试添加: CC="arm-linux-gnueabi-gcc"

You can also add: CFLAGS="-pipe -Wall -O2 ... <other arm-gcc flags>" 您还可以添加: CFLAGS="-pipe -Wall -O2 ... <other arm-gcc flags>"
for better code optimization. 以获得更好的代码优化。

The right way to do this on Ubuntu is to the use the distro-supplied cross-compiler, not a 3rd party one like Linaro. 在Ubuntu上执行此操作的正确方法是使用发行版提供的交叉编译器,而不是像Linaro这样的第三方。 You only need an out-of-distro package when the distro one is not good enough for some reason (like you need some cutting-edge feature which is only in the Linaro toolchain and not yet in the distro). 当由于某种原因发行版不够好时,您只需要发行发行包即可(例如,您需要一些仅在Linaro工具链中尚未发行的尖端功能)。 Hardly anyone needs to do that. 几乎没有人需要这样做。

Install the gcc, g++ crosstollchains, a cross libc and some config tools with: 使用以下命令安装gcc,g ++ crosstollchains,交叉libc和一些配置工具:

apt install crossbuild-essential-armhf

If the software you want to build needs nothing more than the C runtime library then you can build it as is. 如果要构建的软件只需要C运行时库,则可以按原样构建。 If it needs anything more then you need to install cross-build-dependencies. 如果还需要更多内容,则需要安装跨构建依赖项。

  • If the software you want to build is packaged (and called $packagename ), you should be able to: 如果要构建的软件已打包(称为$packagename ),则应该能够:

     dpkg --add-architecture armhf apt update apt build-dep $packagename 

    then build it with 然后用

     dpkg-buildpackage -aarmhf 
  • If it's not packaged you'll need to install build-dependencies, libraries for arch armhf, tools for the native arch (usually amd64 or arm64). 如果未打包,则需要安装构建依赖项,用于arch armhf的库,用于本机arch的工具(通常是amd64或arm64)。 For example: 例如:

     apt-get install sgmltools ghostscript libpng-dev:armhf libssl-dev:armhf 

    would install native ghostscript and sgmltools (for doc-building) and headers/libraries for libpng and libssl for armhf. 会安装本地的ghostscriptsgmltools (用于doc构建),以及libpng头文件/库和libssl的libssl。

More details on the Debian wiki . 有关Debian Wiki的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM