0

I compile a simple Hello World programm with different compilers (from https://github.com/raspberrypi/tools):

./arm-linux-gnueabihf-c++ ~/Desktop/hello.c -o ~/Desktop/myapp -static

The compilation succeeds and furthermore my image looks good:

$ file myapp
myapp: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked,
for GNU/Linux 2.6.26, BuildID[sha1]=3ad3c7c73f773688a654c2107a1d1409c07d0d9a, not
stripped

Still I can't run the image:

$ ./myapp 
-bash: ./myapp: cannot execute binary file: Exec format error

System information:

$ uname -a
Linux alarm 5.4.2-1-ARCH #1 SMP Fri Dec 6 02:43:30 UTC 2019 aarch64 GNU/Linux

I appreciate any help. If more information about my system is needed, let me know, but according to all of the tutorials I read through the procedure seemed quite easy for me. Turned out to be wrong. I also tried different compiler options resp. compilation with CMake. However, none of my methods eventually worked.

2

I haven't completely understood what you have done, but in respect to your own answer it is in general possible to run 32 bit programs on a RasPi running a 32 bit or a 64 bit kernel. You cannot run a 64 bit program on a 32 bit kernel, which is default. For this you must use a 64 bit kernel. Raspbian Buster has a precompiled 64 bit kernel available together with its default 32 bit kernel. You will find this kernels (I use Raspbian Buster Lite):

rpi ~$ ls -1 /boot/kernel*
/boot/kernel7.img
/boot/kernel7l.img
/boot/kernel8.img
/boot/kernel.img

kernel8.img is the 64 bit kernel. You can load it by adding this line at the top of /boot/config.txt:

arm_64bit=1

Now booted with this kernel you can try to run your 64 bit program. But I think you have to link it static because there are no 64 bit libraries available on the RasPi. All other operating system programs are still only 32 bit (they can run on a 64 bit kernel).

| improve this answer | |
  • I have my source code and I wondered why I couldn´t run it. The answer was that I need the aarch64 compiler. You see that I use ARCH Linux 64bit on my RPi. Still I donÄt know why it does not work. – h0ch5tr4355 Apr 1 at 12:49
1

By creating that post, I noticed that aarch64 is the crucial part.

I need aarch64-linux-gnu-g++ for compilation and the resulting image will run directly.

It seems that - unlike Windows - 32bit programs cannot be run on a 64bit architecture.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.