This is a cache of https://discuss.96boards.org/t/cross-compilation-error-when-executing-in-target/5339. It is a snapshot of the page at 2024-10-31T09:00:32.296+0000.
Cross compilation, error when executing in target - Rock960 - 96Boards Forum

Cross compilation, error when executing in target

Hello,

I am having some problems to cross compile a simple hello world and run it on my Rock960 board.

To compile it, I just followed: How to Cross Compile files on X86 Linux System for 96Boards, libsoc & mraa libraries - 96Boards
I did:

$ aarch64-linux-gnu-gcc helloworld.c -o helloworld.arm

But when running it on Rock960, I get the following message:

-bash: ./helloworld.arm: No such file or directory

Back in my host computer, I did:

$ file helloworld.arm 
helloworld.arm: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=e3e1eefc77ac0cd1896b8b0ff8dee7e82941f906, not stripped

I am afraid I do not have ld-linux-aarch64.so.1 in Rock960.

Could anyone give me a hand?

Thank you in advance

Not an answer, but I’ve been compiling pretty big projects right on the board natively. I find it acceptably fast, even without using “make -j4” to compile using multiple cpu cores. Heck, I’m even editing code on there.

This avoids the hassle of specifying -mcpu=cortex-a72.cortex-a53 or -march=armv8a etc., or, as you found, linking against the correct libraries.

This is kinda wonky, but maybe you can build on the board, then run “ldd helloworld.arm” to see what shared objects its using, then bring them back to your cross toolchain?

1 Like

Thanks @Craig_Iannello for your comment. It made me think…

Now I see that the Debian .img is armhf, but I compiled for aarch64.

I will just try with another toolchain.

Thanks again.

try marking it as executable first

$ chmod +x helloworld.arm

Hello @ric96, thanks for your answer.

My binary was already an executable. The problem had to with the toolchain. I was using aarch64, but I had to use armhf.

So, in my host computer:

sudo apt-get install gcc-arm-linux-gnueabihf
sudo apt-get install g++-arm-linux-gnueabihf

Then I compiled it like (I’d better have created a Makefile):

arm-linux-gnueabihf-g++ main.cpp -o helloworld.arm

And on the board:

$ ls -l helloworld.arm
-rwxr-xr-x 1 linaro linaro 8872 Jul 23 07:13 helloworld.arm
$ file helloworld.arm
helloworld.arm: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=2a3c2ec96053fb8df6b1be8d6708d6122572ccf1, not stripped
$ ./helloworld.arm
Hello World!

I am afraid that the Debian Stretch that can be downloaded from 96boards.org is 32 bit. Actually, if you file any other application, you will realize they were compiled for 32 bit:

$ file /bin/grep 
/bin/grep: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=7e64703be475fe7a15523faba11cbc170dfb1346, stripped
$ file /usr/bin/leafpad 
/usr/bin/leafpad: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=eede3f0bf6407aaddf96d3459c9ced304c49bb0a, stripped

Well… it’s fine for me by now. I believe that Ubuntu is aarch64 (64 bit), but I couldn’t make it work. I still have some problems with Ubuntu in SD card.

Hi @albert-rz,

I am afraid that the Debian Stretch that can be downloaded from 96boards.org is 32 bit. Actually, if you file any other application, you will realize they were compiled for 32 bit:

Yes, this is true. The Debian Root File System is built for ARM32 target. Will try to get this for ARM64 as a separate image.

Well… it’s fine for me by now. I believe that Ubuntu is aarch64 (64 bit), but I couldn’t make it work. I still have some problems with Ubuntu in SD card.

Ubuntu image is built for ARM64 and I got no problem with booting from SD card or eMMC.

Thanks,
Mani

Like Mani said, The rootfs userland is 32 bit, but isn’t the kernel is 64 bit? “uname -a” indicates 64 bit arm, if I remember correctly. I’m not home to try it at the moment.

I was able to run a disassembler on boot.img/Image though. Yeps, its aarch64.

Also, just got home and ran file on something I compiled natively on the board:

linaro@linaro-alip:~$ file /usr/local/bin/x64

/usr/local/bin/x64: ELF 64-bit LSB shared object, 
ARM aarch64, version 1 (SYSV), dynamically linked, 
interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0,
BuildID[sha1]=
e4eb06bbf7aa21ed6ff766f47cf52e8a16e65825, 
not stripped

Uh oh, now here’s something I was not expecting:

linaro@linaro-alip:~$ file /bin/ls

/bin/ls: ELF 64-bit LSB shared object, ARM aarch64, 
version 1 (SYSV), dynamically linked, interpreter 
/lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=
a242161239cb1f4ea9b8a7455013295e5473e3ec, stripped

OH!

I’m a dummy. I built this OS image I’m running and forgot I built 64 bit rootfs. The prebuilt boot.img rock960 is still aarch64 though.

Hi!

You are all right. The kernel is 64 bit but the rootfs is 32 bit.

In the end I managed to install Ubuntu Server.

Thank you guys!