Cross-compiling for ARM with Autoconf
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.
Cross Compile a automake project?
you don't have to change anything. autotools comes with full cross-compilation support.
Just pass the proper --host=
flag for your target architecture, e.g.:
./configure --host arm-linux-gnueabihf
This will look for toolchain programs with the given prefix (in the above case, it would look e.g. for a compiler arm-linux-gnueabihf-gcc
) in your current $PATH
. Most cross-compiling toolchains should automatically adhere to this convention.
See also the official documentation
autotools, how to fail if cross compiler cannot be found
When you specify --host=<host-type>
, and this value differs from the result of running the config.guess
script, autoconf
enters cross-compilation mode. Specifically, the variable cross_compiling
is set to yes
.
If the configure script is in 'cross-compilation' mode, it can't run any resulting executable, so there's no way to tell if a resulting binary is a valid 'host' binary or not. Presumably, a large database of file magic values might be able to tell if a valid host binary has been generated. Despite a couple of decades worth of experience built into the autotools, there are some combinatorial problems that can never keep up with all possible architectures and ABIs.
The autoconf
C compiler tests check to see if the compiler - that is $CC
- can build an executable. autoconf
may provide a warning if the compiler is not prefixed with the host triplet, e.g., arm-none-eabi-gcc
, but will not 'fail' if it finds a working compiler, such as the native gcc
.
So, the only way to ensure cross-compilation with the correct compiler is to specify the compiler:
./configure --host=arm-none-eabi CC="arm-none-eabi-gcc"
If this compiler can't build executables, the configure script will fail.
How to install dependencies for a project that is being cross-compiled on an x86 host for an arm target
@artless-noise guides were a good jumping off point, but unfortunately most of the guides weren't helpful in accomplishing what I wanted to do (or if they were, they weren't straightforward in explaining how to accomplish what I needed).
What I ended up doing was using qemu-debootstrap
sudo qemu-debootstrap --arch armhf buster /mnt/data/armhf http://deb.debian.org/debian/
And then just using sudo chroot /mnt/data/armhf
and I had a functioning shell where I could just apt-get
anything I needed, run any scripts and get armhf binaries.
Related Topics
Perl-Mechanize Runs into Limitations - Several Debugging Attempts Started
Bash: Transform Key-Value Lines to CSV Format
Reading Microphone Data by Polling Using Alsa [Or V4L2]
Basic Build Issue Regarding Libs, Pkg-Config and Opencv
Function to Search of Multiple Patterns Using Grep
Why Proc Process Faster Than Others
Implementation of Function Execve (Unistd.H)
Redirecting Output of a C Program to Another C Program with a Bash Script Under Linux
Various Docker Container Paths Have Started Failing with Permission Errors on Linux Mint
Linux: Get a Script to Be Able to Ask The User for a File Name Then Open That File
Using Sftp to Transfer Images from HTML Form to Remote Linux Server Using Perl/Cgi.Pm
How to Make Webdriver Testsuite Created in Windows Machine to Run in a Linux Box