- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我发现了一些关于此错误的未解决问题,但没有一个是相关的。
我在我的虚拟机上写了最简单的 C++ 代码(Ubuntu 14.04.3 LTS,sudo virt-what
输出是 vmware
):
z.cpp:
#include <iostream>
int main(){
std::cout << "hello world" << std::endl;
return 0;
}
并用 g++ z.cpp
编译。尝试调用 ./a.out
时,我在 Q 描述中收到错误,即:
-bash: ./a.out: cannot execute binary file: Exec format error
当编译一个不太不同的 C 代码时:
质量控制:
#include <stdio.h>
int main(){
puts("hello world");
return 0;
}
使用 gcc q.c
我没有遇到任何问题,./a.out
的输出与预期的一样 "hello world"
这是我的dpkg --list | grep 编译器
:
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 位 MSB 可执行文件,PowerPC 或 cisco 4500,版本 1 (SYSV),动态链接(使用共享库),适用于 GNU/Linux 2.6.10,不是剥离
已经回答了,但为了问题的完整性,这里是最后一个造成差异的拼图(虽然我第一次发布 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
没问题。
关于c++ - -bash : ./a.out: 无法执行二进制文件: Exec 格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51378476/
我是一名优秀的程序员,十分优秀!