Cross-compiling for ARM with Autoconf
Solution 1
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.
Solution 2
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:
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
Solution 3
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
Constantin
Started coming here for general C++ questions but thanks to SO I've learned enough to handle many of them on my own now. Now I come for specific library questions and design help. I wanted to say, the people on this site are wonderful. I wish I could sincerely thank everyone for their time and patience.
Updated on October 11, 2020Comments
-
Constantin over 3 years
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...
-
Constantin about 11 yearsYes 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?
-
mikyra about 11 yearsAs 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. -
Constantin about 11 yearsSo I'm pretty much supposed to set up the entire Makefile through environment variables, down to the linker flags such as
-rlink-path
? -
EdH about 11 yearsBasically, yes. This is because cross tool chains are inherently unique. Cross compiling is not for the faint of heart :)
-
Constantin about 11 yearsSo 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.
-
Dr.jacky over 8 yearsI don't even have "/usr/bin/arm-linux-gnueabi-gcc-4.5" ! But I installed it via "apt-get install gcc-arm-linux-gnueabi"
-
jww over 5 years
-prefix=${CSTOOL_DIR}/linux_arm_tool
looks wrong. I think the Autotools options use double-dash, like--prefix=...
.