I found a few open issues on this error, but none was relevant.
I wrote the simplest C++ code on my VM ( Ubuntu 14.04.3 LTS , sudo virt-what
output is vmware
):
z.cpp:
#include <iostream>
int main(){
std::cout << "hello world" << std::endl;
return 0;
}
and compiled with g++ z.cpp
. When trying to call ./a.out
I get the error in the Q description, ie:
-bash: ./a.out: cannot execute binary file: Exec format error
When compiling a not-so-different C-code:
qc:
#include <stdio.h>
int main(){
puts("hello world");
return 0;
}
with gcc qc
I get no problems and the output of ./a.out
is, as expected "hello world"
This is my dpkg --list | grep compiler
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
The problem is clearly in the g++ compiler, since the C-code ( qc
) which runs fine when compiled by gcc
, fails to run when compiled by g++
. However, I have no idea what in the compiler exactly could be wrong
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
Already answered it, but for the sake of the question's completeness, here is the last puzzle piece that made the difference (although I didn't think of checking this when I first posted the Q):
alias g++='/opt/Cross_Tools/powerpc-linux-gnu/bin/powerpc-linux-gnu-g++'
Found the problem...
The g++ command was indeed making a 32-bit application (as can be seen by the output of file a.out
). The reason is that I had an alias I wasn't aware of:
alias g++='/opt/Cross_Tools/powerpc-linux-gnu/bin/powerpc-linux-gnu-g++'
which made my g++ z.cpp
command not use the actual /usr/bin/g++
but the cross-compiler. When compiling with make z
the a.out
was fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.