Cross-compiling for ARM with Autoconf
Asked Answered
S

4

19

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

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 file to check it I get:

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...

Selfconceit answered 5/3, 2013 at 21:58 Comment(0)
S
20

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/bin there was no arm-linux-gnueabi-gcc, I had to:

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-link flags in more advanced compiles.

Selfconceit answered 5/3, 2013 at 22:56 Comment(2)
I don't even have "/usr/bin/arm-linux-gnueabi-gcc-4.5" ! But I installed it via "apt-get install gcc-arm-linux-gnueabi"Areola
-prefix=${CSTOOL_DIR}/linux_arm_tool looks wrong. I think the Autotools options use double-dash, like --prefix=....Bowler
J
12

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

According to ./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:

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

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

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

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

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

  • 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
    
Jobey answered 16/1, 2014 at 23:17 Comment(0)
W
2

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)

Check out some guides for various projects, for instance: 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

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

 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

Whitecap answered 5/3, 2013 at 22:5 Comment(5)
Yes that makes perfect sense, and expected as much. I just couldn't figure out where the compiling was going wrong. What is the point of the --target flag if it doesn't automatically use the correct compilers and linkers?Selfconceit
As long as you are not building a compiler (looking at the libjpeg.so mentioned I don't think so) the --target flag won't be of any use anyways. --target specifies the architecture of the machine for which the binary created will generate output. Thus an assembler build on machine A that later runs on machine B to assemble code for machine C would use: --buid=A --host=B --target=C. If the generated binary doesn't generate any code the --target flag doesn't make any change.Waist
So I'm pretty much supposed to set up the entire Makefile through environment variables, down to the linker flags such as -rlink-path?Selfconceit
Basically, yes. This is because cross tool chains are inherently unique. Cross compiling is not for the faint of heart :)Whitecap
So I figured out that what was really going on was that autoconf does indeed attempt to find your binaries, but it was failing for me.Selfconceit
A
0

# 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
Apotheosize answered 11/10, 2018 at 2:17 Comment(1)
arm-linux-gnueabi-gcc doesn’t exist on Ubuntu 22.04, but gcc-arm-linux-gnueabi looks like the package that is needed here.Insnare

© 2022 - 2024 — McMap. All rights reserved.