繁体   English   中英

无法执行二进制文件:在 WSL 环境中编译的二进制文件的 Exec 格式错误

[英]cannot execute binary file: Exec format error for a binary compiled in WSL environment

我最近开始研究 WSL 环境。 我在 WSL 环境中编译了一个类型为“ELF 64 位 LSB 共享对象”的程序,但是当我尝试在同一环境中运行它时,它会抛出错误“无法执行二进制文件:Exec 格式错误”。

我不确定我在这里缺少什么。 我怎样才能运行二进制文件。 请建议。

kshitij@APL-5CD010D2WP:~/runtime/bin$ ioc_broker &
[1] 3579
kshitij@APL-5CD010D2WP:~/runtime/bin$ bash: /bin/ioc_broker: cannot execute binary file: Exec format error
^C
[1]+  Exit 126                ioc_broker
kshitij@APL-5CD010D2WP:~/runtime/bin$ file ioc_broker 
ioc_broker: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=aa1e76d798d46d45f131cb53de8f947ddb4c8526, for GNU/Linux 3.2.0, not stripped
kshitij@APL-5CD010D2WP:~/runtime/bin$ uname -srv
Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022
kshitij@APL-5CD010D2WP:~/runtime/bin$ 

kshitij@APL-5CD010D2WP:/mnt/d/src/myproject/build$ uname -a
Linux APL-5CD010D2WP 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

我已经使用 cmake 编译了二进制文件,其中我没有指定任何关于正在使用的编译器的具体信息。

kshitij@APL-5CD010D2WP:/mnt/d/src/myproject/build$ cmake -DCMAKE_INSTALL_PREFIX=/home/kshitij/runtime ..
-- The CXX compiler identification is GNU 9.4.0
-- Check for working CXX compiler: /bin/c++
-- Check for working CXX compiler: /bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Line: 57 Using COMMON_API_VERSION 3.1.12

uname -srv
Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022

尝试uname -a代替。 它应该将 kernel 标识为i686x86_64

我希望您的 kernel 显示i686 ,在这种情况下,您已经安装了 32 位 WSL2 并试图在其上运行 64 位二进制文件。 这显然行不通——您需要 64 位 kernel 才能运行 64 位二进制文件。

更新:

我看到 x86_64

好吧,我的猜测是错误的。 Exec format error的另一个原因是文件以某种方式损坏。

一种可能的损坏原因是磁盘空间不足并且文件被截断。 检查df -h. output 如果空间很大,请尝试重新构建二进制文件。

也可以试试eu-readelf -a ioc_broker —— eu-readelf擅长警告损坏的 ELF 文件。

最后,在/var/log/messages中查找任何 kernel 警告——您可能有坏磁盘块或其他东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM