not found" when trying to execute a file I ran into the strangest problem I have ever encountered. I am using cross compilation of a...">

"sh: ./ <file> not found" when trying to execute a file

I ran into the strangest problem I have ever encountered. I am using cross compilation of an application for an ARM processor with Linux on board. I use buildroot and everything goes well until I try to run the application in the target environment: I get -sh: ./hw: not found . For instance:.

 $ cat /tmp/test.cpp #include <cstdio> #include <vector> int main(int argc, char** argv){ printf("Hello Kitty!\n"); return 0; } $ ./arm-linux-g++ -march=armv7-a /tmp/test.cpp -o /tftpboot/hw 

Download the target executable then issue on target:

 # ./hw -sh: ./hw: Permission denied # chmod +x ./hw # ./hw -sh: ./hw: not found # ls -l ./hw -rwxr-xr-x 1 root root 6103 Jan 1 03:40 ./hw 

There is more: when creating using the distro compiler, for example arm-linux-gnueabi-g++ -march=armv7-a /tmp/test.cpp -o /tftpboot/hw , the application works fine!

I compared executables with readelf -a -W /tftpboot/hw but didn't notice much. I inserted both outputs here . The only thing I noticed was the lines of Version5 EABI, soft-float ABI vs Version5 EABI . I tried to remove the difference by skipping any of -mfloat-abi=softfp and -mfloat-abi=soft , but the compiler seems to ignore it. I suppose, however, that doesn't really matter, since the compiler doesn't even warn you.

I also thought, perhaps sh is outputting this error if the executable is somehow incompatible. But on my host computer, I see another error in this case, for example:

 $ sh /tftpboot/hw /tftpboot/hw: 1: /tftpboot/hw: Syntax error: word unexpected (expecting ")") 
+6
source share
1 answer

sh prints this strange error because it is trying to run your program as a shell script!

Your ./hw: not found error is probably due to the fact that the dynamic linker (AKA ELF interpreter) was not found. Try compiling it as a static program using -static or starting it using the dynamic loader: # /lib/ld-linux.so.2 ./hw or something like that.

If the problem is that the dynamic loader is named differently in your toolchain and in the runtime, you can fix it:

  • At runtime: with a symbolic link.
  • In the -Wl,--dynamic-linker=/lib/ld-linux.so.2 : use -Wl,--dynamic-linker=/lib/ld-linux.so.2
+8
source

Source: https://habr.com/ru/post/971857/


All Articles