Search code examples
androidld

Error executing a file: bash: ./Test.elf: cannot execute: required file not found


Today I made a test program in C, which is a simple "Hello world.",

#include <stdio.h>

int _start(){
  printf("Hello, world!\n");
  return 0;
}

but I wanted to compile it in another way. I first compiled it with

gcc -c Test.c -o Test.o

and then linked it with

ld Test.o -lc -o Test.elf

. -lc to use the libc.so library for printf, but for some reason, when I try to run it with ./Test.elf, it tells me this error: bash: . /Test.elf: cannot execute: required file not found. If I don't try to run with gdb, it tells me that the error code is 127. As a matter of fact, I am trying all of this from Android, (to be able to program in aarch64), which I don't know if it influences this error. Could someone help me?

Edit: I tried with this: ld Main.o -o Main.elf -L. -lLibr --dynamic-linker=/system/lib64/ld-android.so And now I get this error: bash: ./Main.elf: Permission denied I send chmod 777 Test.elf but I always get the same error.


Solution

  • I have already solved it, the only thing I had to do was add this argument to the ld command -dynamic-linker=/system/bin/linker64 (on Android) and also this other one -pie because after Android 5, this other argument is necessary.