Running "make distclean" first solved it.
./configure --host=aarch64-linux-gnu --prefix=/opt/install-arm64/papi-5.6.1.0 --with-ffsll --with-walltimer=cycle --with-tls=__thread --with-virtualtimer=perfctr --with-perf-events --with-arch=aarch64 --with-CPU=arm
make
sudo make install
To install those binary files in /opt/install-arm64/papi-5.6.1.0.
Answer from LuisM on Stack Overflowandroid - Cross-compiling for arm64 - Stack Overflow
Instructions on how to cross compile Windows (amd64 -> arm64)
how can I cross compile an assembly and a .c file to arm64 on macos?
c++ - Cross-compile to ARM64 (AARCH64) on Intel 64-bit Red Hat 7.5 can't find dlfcn.h, cstddef.h, etc - Stack Overflow
Videos
Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation.
You need to be careful on what flavour of linux and binutils you have on your target system. The newest stuff is hardfloat, in this case you would do:
sudo apt-get install gcc-arm-linux-gnueabihf
This brings in the complete cross-compile environment, including binutils.
For using this GCC in the build process write:
CC=arm-linux-gnueabihf-gcc make
64-bit ARM
For 64-bit ARM, the toolchain prefix is aarch64 and usage is:
sudo apt install gcc-aarch64-linux-gnu
aarch64-linux-gnu-gcc -o main.out main.c
You can try it out on this C hello world with QEMU:
main.c
#include <stdio.h>
int main(void) {
puts("hello");
}
and then:
sudo apt install qemu-user
qemu-aarch64 main.out
will output:
hello
Then a few fun things you can do to quickly see that ARM is actually running under the hood:
- GDB step debug it: https://stackoverflow.com/questions/20590155/how-to-single-step-arm-assembly-in-gdb-on-qemu/51310791#51310791
- log the executed ARM instructions with:
qemu-aarch64 -d in_asm,out_asm main.outhttps://stackoverflow.com/questions/13005303/how-does-native-android-code-written-for-arm-run-on-x86/44505097#44505097
Tested in Ubuntu 19.10.
For reliability in serious applications, the disk image provider must also provide a compatible cross compiler
Although you can install a cross compiler with apt conveniently, I must warn you that this is not necessarily reliable unless explicitly supported by the image provider.
If you pick the cross compiler wrongly, the following may happen:
- the dynamic linker is at the wrong path: https://stackoverflow.com/questions/31929092/trying-to-run-a-cross-compiled-executable-on-target-device-fails-with-no-such-f/49993116#49993116
- binary incompatibility with the glibc and any other libraries you link against: https://stackoverflow.com/questions/11107263/how-compatible-are-different-versions-of-glibc
Raspberry PI cross compilation
For RPI in particular, the provided cross compilers are available at: https://github.com/raspberrypi/tools and can be used as explained at: https://raspberrypi.stackexchange.com/questions/64273/installing-raspberry-pi-cross-compiler/83215#83215
git clone https://github.com/raspberrypi/tools
export PATH="$(pwd)/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}"
printf '#include <stdio.h>\nint main() { puts("hello world"); }\n' > hello_world.c
printf '#include <iostream>\nint main() { std::cout << "hello world" << std::endl; }\n' > hello_world.cpp
arm-linux-gnueabihf-gcc -std=c99 -o hello_world_c hello_world.c
arm-linux-gnueabihf-g++ -std=c++11 -o hello_world_cpp hello_world.cpp
Ubuntu cross compilation
If you want to cross compile for Ubuntu arm64, I have never been able to find a clear reference on which cross compilers support which distro version: What are the officially supported cross compilers for Ubuntu server alternative architectures like ARM?
Buildroot
My favorite alternative is to build your own image with Buildroot: https://stackoverflow.com/questions/47557262/how-to-download-the-torvalds-linux-kernel-master-recompile-it-and-boot-it-wi/49349237#49349237
This builds everything from source, including the toolchain and the image, and ensures that everything is compatible.
Hello,
I know this is a beginner question - I have been trying for hours to run a small kernel with qemu-system-aarch64 on macos. I want to compile without standard library and have written a linker script to correctly place the _start function.
I have the following files: boot.S kernel.c link.ld
I tried a lot. When using "clang -target aarch64 -nostdlib boot.S kernel.c -o kernel.o" to link it afterwards I get a linker error. I also tried the -c flag as written in the man page of gcc.
sudo yum install binutils-aarch64-linux-gnu.x86_64 gcc-aarch64-linux-gnu.x86_64 gcc-c++-aarch64-linux-gnu.x86_
64
will result in:
Installing:
binutils-aarch64-linux-gnu x86_64 2.38-3.el8 epel 6.1 M
gcc-aarch64-linux-gnu x86_64 12.1.1-2.el8 epel 30 M
gcc-c++-aarch64-linux-gnu x86_64 12.1.1-2.el8 epel 11 M
Installing dependencies:
cross-binutils-common noarch 2.38-3.el8 epel 2.7 M
cross-gcc-common noarch 12.1.1-2.el8 epel 2.8 M
I faced a similar problem for a while and unfortunately I learned that developing on RedHat is not as easy as on Debian (at least for me). Finally I managed to install a cross compile toolchain for aarch64 and I'm using it now. The version of redHat that I am using is : Red Hat Enterprise Linux Server release 7.9 (Maipo) and I downloaded the following packages for this release.
- cross-gcc-common-4.8.5-16.el7.1.noarch.rpm
- cross-binutils-common-2.27-9.el7.1.noarch.rpm
- binutils-aarch64-linux-gnu-2.27-9.el7.1.x86_64.rpm
- gcc-aarch64-linux-gnu-4.8.5-16.el7.1.x86_64.rpm
Then install the packages in order with the command "rpm -Uvh <package_name>.rpm"(You most probably need sudo).
If everything goes well, you can try the command "aarch64-linux-gnu-gcc -v" to show version of aarch64 gcc.