ocaml - 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]
解决方案
"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.
推荐阅读
- azure - 由于 X-ORIGINAL-URL 标头(CVE-2018-14773),Cloudflare 阻止了我们的“子域之间”url 重写为 403
- mongodb - 如何使用代码将 MongoDB 中的数据类型更改为 pymongo (Python)
- android - 从 Cloud Firestore 中获取数据
- angular - 如果在表单中,角度 ng-autocomplete 不会设置初始值
- java - Java 开放地理工具
- google-apps-script - 如何避免根据同一日期范围内的列值插入一行数据?
- shell - Linux从文本行内部剪切字段
- typescript - 如何使用仅适用于特定 IP 地址的 AWS CDK 部署 S3 存储桶(NotIpAddress 条件)?
- laravel - 刷新页面时保持在数据表中输入的搜索值vue.js
- css - 子选择器和相邻兄弟选择器有什么区别?