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

eqoofvh9  于 2023-01-29  发布在  其他
关注(0)|答案(1)|浏览(783)

我最近开始在WSL环境下工作,我在WSL环境下编译了一个程序,它的类型是“ELF 64位LSB共享对象”,但当我试图在相同的环境下运行它时,它抛出了一个错误“无法执行二进制文件:执行格式错误””。
我不确定我在这里错过了什么。我如何运行二进制文件。请提出建议。

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编译了二进制文件,在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
blmhpbnm

blmhpbnm1#

uname -srv
Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022
尝试uname -a,它应该将内核标识为i686x86_64
我希望您的内核是i686,在这种情况下,您已经安装了一个32位的WSL2,并试图在其上运行一个64位的二进制文件,但由于显而易见的原因,这行不通--您需要一个64位的内核来运行64位的二进制文件。

    • 更新日期:**

我看到x86_64
好的,我的猜测是错误的。Exec format error的另一个原因是文件在某种程度上损坏了。
损坏的一个可能原因是磁盘空间不足,文件被截断。请检查df -h .输出,如果有大量空间,请尝试重新生成二进制文件。
还可以尝试eu-readelf -a ioc_broker--eu-readelf擅长警告损坏的ELF文件。
最后,在/var/log/messages中查找任何内核警告--您可能有一个坏的磁盘块或其他东西。

相关问题