server - Exec format error of gcc-compiled Hello World c++ - Ask Ubuntu
i know there many similar questions error message here. cannot find solution yet.
on aws ubuntu server, wrote c++ hello, world program
#include <iostream> using namespace std; int main(){ cout<<"hello, world!"<<endl; return 0; } and compiled:
ubuntu@ip-xxxxx:~/dev/c++$ g++ -c ./test.cc -o out ubuntu@ip-xxxxx:~/dev/c++$ chmod a+x out ubuntu@ip-xxxxx:~/dev/c++$ ./out -bash: ./out: cannot execute binary file: exec format error ubuntu@ip-xxxxx:~/dev/c++$ file ./out ./out: elf 64-bit lsb relocatable, x86-64, version 1 (sysv), not stripped ubuntu@ip-xxxxx:~/dev/c++$ uname -a linux ip-xxxxx 3.13.0-48-generic #80-ubuntu smp thu mar 12 11:16:15 utc 2015 x86_64 x86_64 x86_64 gnu/linux ubuntu@ip-xxxxx:~/dev/c++$ gcc --version gcc (ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4 it seems architecture x86-64 same each other. problem here? have add more c++ flags?
the -c flag tells g++ compile source code object code, stop short of linking necessary libraries create standalone executable binary. man gcc:
-c compile or assemble source files, not link. linking stage not done. ultimate output in form of object file each source file. to create executable program, simple run command again without -c flag:
g++ test.cc -o out followed by
./out (the executable flag set default - explicit chmod should not required).
Comments
Post a Comment