3

I have written simple Hello world program and compiled it with gcc-arm-linux-gnueabi compiler. It compiles well but when i try to execute it on ARM machine it complains "no such file or directory". I think gcc-arm-linux-gnueabi is for embedded Linux only due to e(mbedded)abi. Is it different from ARM Linux ABI?

Please help me to solve this problem

code is here

#include "stdio.h"

int main(void) {
  printf("Hello world !\n");
  return 0;
}

compiled as

arm-linux-gnueabi-gcc -Wall -o crosscomp hello.c

When i execute this crosscomp on target ARM machine error is crosscomp no such file or dir

EDIT When I was using arm-linux-gnueabi-gcc the entry point was not matching with the target machine entry point (readelf -l crosscom) but when I compiled with aarch64-linux-gnu-gcc entry point matched with target machine. But now error becomes permission denied on ./crosscomp. I tried with sudo which says crosscomp: no such command.

Note I posted same question on askubuntu https://askubuntu.com/questions/904685/cross-compilation-for-arm-error-no-such-file-or-directory but got no response.

The output of readelf is as below

ELF Header:

 Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           AArch64
  Version:                           0x1
  Entry point address:               0x400470
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4488 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         8
  Size of section headers:           64 (bytes)
  Number of section headers:         29
  Section header string table index: 26
incompetent
  • 1,715
  • 18
  • 29
  • what's the output of `ls -l crosscomp` ? – cleblanc Apr 14 '17 at 13:36
  • Ok, in short this error is because the toolchain is not meant for Target ARM processor, you need to use the exact same toolchain which is used to compile the rootfs for target board. – Gaurav Pathak Apr 14 '17 at 13:41
  • 1
    Thanks Gaurav. Any suggestion to discover that toolchain – incompetent Apr 14 '17 at 13:44
  • You can refer this [link](http://stackoverflow.com/questions/2387040/how-to-retrieve-the-gcc-version-used-to-compile-a-given-elf-executable). From any binary on that target rootfs, maybe busybox. If the comments are not stripped out. – Gaurav Pathak Apr 14 '17 at 13:55
  • Refer the vendor website. It should have toolchain or BSP download link. Can you tell me, where have you got the BSP for this board or how have you compiled the filesystem for it? – Gaurav Pathak Apr 14 '17 at 13:59
  • this is for a linux install on some ARM? – old_timer Apr 14 '17 at 15:09
  • @old_timer yes target is Linux on ARM – incompetent Apr 14 '17 at 17:44
  • I am starting to think we may also need to know exactly which ARM CPU this is – zwol Apr 14 '17 at 20:39
  • @zwol Only info available for CPU is that it is standardized as ARMv8 – incompetent Apr 14 '17 at 20:41
  • There are a _lot_ of different CPUs under that umbrella. Another thing you could tell us on Monday is the output of `uname -a` and `cat /proc/cpuinfo` executed on the target machine – zwol Apr 14 '17 at 21:51
  • Possible duplicate of [Trying to run a cross-compiled executable on target device fails with: No such file or directory](https://stackoverflow.com/questions/31929092/trying-to-run-a-cross-compiled-executable-on-target-device-fails-with-no-such-f) – Ciro Santilli OurBigBook.com Apr 24 '18 at 03:48

1 Answers1

3

This peculiar error message happens when the dynamic loader required by a particular executable is missing.

You can find out the name of the dynamic loader that you need by applying readelf to the problem executable. On my x86-64 Linux box, for example

$ readelf -l /bin/ls | grep 'program interpreter'
  [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

("program interpreter" is another name for "dynamic loader".)

So, run the above command on your crosscomp binary on your development box. (If you don't have readelf or you get error messages, try arm-linux-gnueabi-readelf.) The file named after "program interpreter:" needs to exist on your target ARM machine. If you don't know where to get it, please post the output of the above command + ls -l of the directory that should have the missing file in it.

zwol
  • 135,547
  • 38
  • 252
  • 361
  • thanks zwol I have confirmed that entry point and loader are same/accurate for target machine. when I straced crosscomp, second syscall is write with string permission denied despite it is printing command not found. I badly stuck – incompetent Apr 14 '17 at 17:43
  • @shami Could you please copy and paste the **complete and unedited** strace output into the question? Also the output of `ls -l ./crosscomp` and the output of `readelf -e ./crosscomp`. – zwol Apr 14 '17 at 18:09
  • Thanks I will be able to do this on Monday – incompetent Apr 14 '17 at 19:17
  • @shami One more thing; it's a silly unlikely problem, but just to make sure, do `chmod +x ./crosscomp` and then try running it again. – zwol Apr 14 '17 at 19:48
  • the file flags are -rwxrwxr-x 1 readelf has very long output. how to add that? – incompetent Apr 14 '17 at 19:57
  • @shami Only the top part is interesting: `readelf -e ./crosscomp | sed '/^$/q'` and edit the output into the question. – zwol Apr 14 '17 at 20:04
  • How about the strace output? Is that what you won't be able to provide till Monday? – zwol Apr 14 '17 at 20:28
  • yes if addresses are not important then string passed to write (2nd syscall) was permission denied despite it was printing command not found when executed with sudo – incompetent Apr 14 '17 at 20:31
  • The thing is, I want to know what the *first* syscall was, in exact detail. – zwol Apr 14 '17 at 20:32
  • first call was execve with path to crosscomp. I can post exact detail on Monday – incompetent Apr 14 '17 at 20:37
  • problem has been solved. There was a silly mistake on my side when I checked file flags of crosscomp I checked these on development machine. When I checked file permissions on target machine, the file was not executable :(. I just executed chmode +x it started to work :) Thanks for cooperation. My first error was interpreter mismatch, plz change the ls part of your answer to suggest chmod +X. It will help others to find solution quickly. – incompetent Apr 17 '17 at 07:06