-bash:/a.out:无法执行二进制文件:Exec格式错误
-bash: ./a.out: cannot execute binary file: Exec format error
我在这个错误上发现了一些悬而未决的问题,但没有一个是相关的。
我在我的VM上写了最简单的C++代码(Ubuntu 14.04.3 LTS,sudo virt-what
输出为vmware
):
z.cpp:
#include <iostream>
int main(){
std::cout << "hello world" << std::endl;
return 0;
}
并用CCD_ 3编译。当尝试调用./a.out
时,我在Q描述中得到错误,即:
-bash:/a.out:无法执行二进制文件:Exec格式错误
编译一个不那么不同的C代码时:
q.c:
#include <stdio.h>
int main(){
puts("hello world");
return 0;
}
有了gcc q.c
,我没有问题,./a.out
的输出与预期的"hello world"
一样
这是我的dpkg --list | grep compiler
:
ii g++ 4:4.8.2-1ubuntu6 i386 GNU C++ compiler
ii g++-4.8 4.8.4-2ubuntu1~14.04 i386 GNU C++ compiler
ii gcc 4:4.8.2-1ubuntu6 i386 GNU C compiler
ii gcc-4.8 4.8.4-2ubuntu1~14.04 i386 GNU C compiler
ii hardening-includes 2.5ubuntu2.1 all Makefile for enabling compiler flags for security hardening
ii libllvm3.5:i386 1:3.5-4ubuntu2~trusty2 i386 Modular compiler and toolchain technologies, runtime library
ii libxkbcommon0:i386 0.4.1-0ubuntu1 i386 library interface to the XKB compiler - shared library
问题显然存在于g++编译器中,因为用gcc
编译时运行良好的C代码(q.c
(,用g++
编译时无法运行。然而,我不知道编译器中到底有什么可能是错误的
file a.out = a.out: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.10, not stripped
已经回答了,但为了问题的完整性,这里是最后一个产生差异的拼图(尽管我第一次发布Q时没有想过检查这个(:
alias g++='/opt/Cross_Tools/powerpc-linux-gnu/bin/powerpc-linux-gnu-g++'
发现问题。。。
g++命令实际上是在制作一个32位的应用程序(从file a.out
的输出中可以看出(。原因是我有一个我不知道的别名:
alias g++='/opt/Cross_Tools/powerpc-linux-gnu/bin/powerpc-linux-gnu-g++'
这使得我的g++ z.cpp
命令不使用实际的/usr/bin/g++
,而是使用交叉编译器。当用make z
编译时,a.out
是好的。
相关文章:
- 正在读取二进制文件(is_open)
- 在C++中将类(带有Vector成员)保存为二进制文件
- 如何从二进制文件中读取字符串
- 保存/加载大量短数组到二进制文件
- 从二进制文件中读取整数数组
- Android 在编译二进制文件时重建静态库
- 在 C++ 中将双精度变量写入二进制文件
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- C++:实际上不是从二进制文件中读取
- 如何从二进制文件中的给定符号中获取调用程序图
- 将内部带有矢量的结构保存/读取到二进制文件中
- 编译多个C++文件.调用二进制文件以运行代码
- 如何使用位字段将数据从二进制文件复制到结构中?
- uint8_t同一二进制文件的不同十进制值
- C++单个生成文件多个二进制文件
- 尝试将数字写入二进制文件时引发异常
- -bash:/a.out:无法执行二进制文件:Exec格式错误
- bash:./main:无法执行二进制文件:Exec格式错误
- bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误
- 使用apache thrift通过exec执行二进制文件