I am trying to compile a helloworld.c code
#include<stdio.h>
int main(){
printf("Hello World");
return 0;
}
on a Linux machine. Below is the uname- a result for the machine, which states that the machine is 64 bit.
uname-a : Linux pascal 2.6.32-358.23.2.el6.x86_64 #1 SMP Sat Sep 14 05:32:37 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
On running the gcc command I am getting the following errors:
[pascal]/user/gasharma/workspaceC++:/>gcc -c helloworld.c
/tmp/ccpg1Atk.s: Assembler messages:
/tmp/ccpg1Atk.s:11: Error: suffix or operands invalid for `push'
/tmp/ccpg1Atk.s:12: Error: suffix or operands invalid for `push'
/tmp/ccpg1Atk.s:14: Error: suffix or operands invalid for `push'
/tmp/ccpg1Atk.s:20: Error: suffix or operands invalid for `pop'
/tmp/ccpg1Atk.s:21: Error: suffix or operands invalid for `pop'
Here is the output for gcc -v:
[pascal]/user/gasharma/workspaceC++:/>gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2.4/configure --prefix=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local
Thread model: posix
gcc version 4.2.4
On closer inspection of the above, I do see that the target is i686 (which I am not sure is 32 or 64 bit). My strong guess is that it is 32 bit. I Googled for sometime and results indicated that the problem could be with the 32 bit compiler on 64 bit machine. However, some results also pointed at use of -m32 and -m64 options to execute a successful compile run.
I did a gcc run with -m64 and it resulted in the below error.
[pascal]/user/gasharma/workspaceC++:/>gcc -c -m64 helloworld.c
helloworld.c:1: sorry, unimplemented: 64-bit mode not compiled in
I have six questions here:
1) i686 in the target represents 32 or 64 bit machine? How can I make that distinction? Generally i386 refers to 32bit and x86_64 to 64 bit.
2) How can I run a simple helloworld.c in my case? When, why and how do I use -m32 and -64 options?
3) Does this have something to do with the assembler or compiler?
4) What does "sorry, unimplemented: 64-bit mode not compiled in" imply?
5) What is the meaning of "Configured with: ../gcc-4.2.4/configure --prefix=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local"?
6) Why the target machine is not x86_64 under the gcc when I am running 64 bit machine?
I will really appreciate someone taking time and answering my above questions. Thanks in advance!
which gccand verify that you are running thegccfrom your distro package. The error you see is becausegccis generating 32 bit code even though it shouldn't, and the assembler correctly expects 64 bit.gcc -m32should work however, since that should invoke the assembler in 32 bit mode too (but would obviously create 32 bit output). Also add-voption togccto see how it invokes the tools. - Jester