C语言 使用 Autoconf 为 ARM 交叉编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15234959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:34:47  来源:igfitidea点击:

Cross-compiling for ARM with Autoconf

ccross-compilingautoconf

提问by Constantin

I am having trouble cross-compiling a library for my arm board using autconf.

我在使用 autconf 为我的 arm 板交叉编译库时遇到问题。

I am using this line:

我正在使用这一行:

./configure --target=arm-linux --host=arm-linux --prefix=/bla/bla/bla/linux_arm_tool CFLAGS='-m32'
make
make install

When I do fileto check it I get:

当我file检查它时,我得到:

libjpeg.so.8.4.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped

That doesn't seem right at all, but I tried using it anyway... and I get:

这似乎根本不对,但无论如何我都尝试使用它......我得到:

/usr/lib/gcc/arm-linux-gnueabi/4.5.3/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible /bla/bla/bla/bla/../linux_arm_tool/lib/libjpeg.so when searching for -ljpeg

I'm at a loss, I've been googling for an hour now...

我不知所措,我已经在谷歌上搜索了一个小时......

回答by Constantin

So I knew I've cross compiled before using really basic method calls and I figured out why I've gotten away with this before after examining the output:

所以我知道我在使用真正基本的方法调用之前已经进行了交叉编译,并且在检查输出之后我弄清楚了为什么我之前没有这样做:

checking for arm-linux-gnueabi-gcc... no
checking for gcc... gcc
...
...
checking for arm-linux-gnueabi-gcc... gcc

In my /usr/binthere was no arm-linux-gnueabi-gcc, I had to:

在我/usr/bin没有arm-linux-gnueabi-gcc,我不得不:

ln -s /usr/bin/arm-linux-gnueabi-gcc-4.5 /usr/bin/arm-linux-gnueabi-gcc


I successfully cross-compiled using:

我使用以下方法成功交叉编译:

./configure --host=arm-linux-gnueabi -prefix=${CSTOOL_DIR}/linux_arm_tool

as for linking ... I still have to check some things, but I am going to assume I might need to throw some -rpath-linkflags in more advanced compiles.

至于链接......我仍然需要检查一些东西,但我假设我可能需要-rpath-link在更高级的编译中抛出一些标志。

回答by Brad Grissom

I think the problem could be restated more generally as: "How do I use Autoconf to cross compile for ARM?"

我认为这个问题可以更笼统地表述为:“我如何使用 Autoconf 为 ARM 进行交叉编译?”

According to ./configure -h:

根据./configure -h

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

The official GNU documentation is helpful for answering this question:

GNU 官方文档有助于回答这个问题:

http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Hosts-and-Cross_002dCompilation.html

http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Hosts-and-Cross_002dCompilation.html

Note when they defining the usage of --hostand and --build:

请注意,当他们定义--hostand 和 and的用法时--build

Therefore, whenever you specify --host, be sure to specify --build too.

And here is an example that I just used to configure iperffor my embedded ARM platform:

这是我刚刚用于iperf为我的嵌入式 ARM 平台配置的示例:

First of all the "./configure" script is actually called "Autoconf" which really helps for google-ing. The idea here is to:

首先,“./configure”脚本实际上被称为“Autoconf”,它对google-ing很有帮助。这里的想法是:

  • Have your cross compilers in your current $PATH
  • Set the CC and CXX environment variables to point to the cross compilers
  • Give the right --host and --build

    buildpath    <--- my little script to setup my $PATH
    export CC=arm_v5t_le-gcc
    export CXX=arm_v5t_le-g++
    ./configure --host=armv5tl-montavista-linux-gnueabi --build=x86_64-linux-gnu
    
  • 在当前的 $PATH 中安装交叉编译器
  • 将 CC 和 CXX 环境变量设置为指向交叉编译器
  • 提供正确的 --host 和 --build

    buildpath    <--- my little script to setup my $PATH
    export CC=arm_v5t_le-gcc
    export CXX=arm_v5t_le-g++
    ./configure --host=armv5tl-montavista-linux-gnueabi --build=x86_64-linux-gnu
    

回答by EdH

You need to override the environment variables CC, LD, and other pertinent ones. Setting those switches doesn't tell configure where your cross tool chain is (it could be anywhere)

您需要覆盖环境变量 CC、LD 和其他相关变量。设置这些开关不会告诉配置你的交叉工具链在哪里(它可以在任何地方)

Check out some guides for various projects, for instance: http://wiki.wxwidgets.org/Cross-Compiling_Under_Linux

查看各种项目的一些指南,例如:http: //wiki.wxwidgets.org/Cross-Compiling_Under_Linux

Also, here is a script I made to setup cross compile for node.js - same idea: https://gist.github.com/edhemphill/5094239

另外,这是我为 node.js 设置交叉编译的脚本 - 相同的想法:https: //gist.github.com/edhemphill/5094239

The libjpeg is not going to work b/c it's a x86 binary, you need it to say:

libjpeg 不能工作 b/c 它是一个 x86 二进制文件,你需要它说:

 ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, not stripped

or similar.

或类似。

This is the reason you are getting a skipping incompatible

这就是你得到一个的原因 skipping incompatible

回答by x4444

# Install arm-linux-gnueabi packages
apt-get install libc6-armel-cross libc6-dev-armel-cross \
binutils-arm-linux-gnueabi arm-linux-gnueabi-gcc libncurses5-dev

./configure --target=arm-linux-gnueabi --host=arm-linux-gnueabi
...
checking for arm-linux-gnueabi-gcc... arm-linux-gnueabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabi-gcc accepts -g... yes
checking for arm-linux-gnueabi-gcc option to accept ISO C89... none needed
checking whether arm-linux-gnueabi-gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of arm-linux-gnueabi-gcc... gcc3
...

make
arm-linux-gnueabi-gcc -DPACKAGE_NAME=\"Tutorial\ Program\" -DPACKAGE_TARNAME=\"tutorial-program\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"Tutorial\ Program\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"tutorial-program\" -DVERSION=\"1.0\" -I.     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c