首页 > 解决方案 > lubuntu does not see executable file generated by ocamlopt on NixOS

问题描述

i created executable "standalone" file in NixOS (x86_64) using "ocamlopt" native compiler with option -linkall. and the generated program is executed in NixOS. so far so good

after that i tried to execute this file under Lubuntu

lubuntu@lubuntu:~/Documents$ uname -a
Linux lubuntu 4.18.0-10-generic #11-Ubuntu SMP Thu Oct 11 15:13:55 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

but recieved:

lubuntu@lubuntu:~/Documents$ ./a.out 
bash: ./a.out: No such file or directory

i am quite sure that architecture is suitable:

lubuntu@lubuntu:~/Documents$ objdump -h a.out

a.out:     file format elf64-x86-64

what i did wrong? on NixOS, on OCaml, on Lubuntu?

Tnx in advance

UDP: my NixOS distro:

$> uname -a
Linux cat 4.19.36 #1-NixOS SMP Sat Apr 20 07:16:05 UTC 2019 x86_64 GNU/Linux

ocaml:

$> ocamlopt -v                                                                                         
The OCaml native-code compiler, version 4.06.1   

UDP2:

$> readelf -a a.out | grep ld-
      [Requesting program interpreter: /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/ld-linux-x86-64.so.2]

标签: ocamlx86-64executablenixos

解决方案


"No such file or directory" (ENOENT) when trying to execute a file that does exist usually means that its dynamic linker path (ELF interpreter) doesn't exist. It's exactly the same error for the same reason you'd get from executing a text file that started with #!/non-existant/path

Use strace ./a.out to see that the only system call is the execve which fails.

Most GNU/Linux distros use /lib64/ld-linux-x86-64.so.2. For example file /bin/ls on my Arch GNU/Linux desktop shows:

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=4fef2dc9762eb7d4593f402a65cc02bb3d4c48de, for GNU/Linux 3.2.0, stripped

Presumably NixOS, or at least ocamlopt on NixOS, uses a different path. Use file to check. (Or readelf -a to show the ELF program headers will also dump the interpreter path.)

ldd can also show the interpreter path, but IIRC fails if the path isn't valid.


推荐阅读