简体   繁体   中英

Is i686 32 bit? Why does my gcc/g++ fail compiling .cpp and .c files?

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!

  1. i686 is a reference to the Intel CPU architecture used for the the Pentium Pro and Pentium II processors. It also means that the target is 32-bit x86 code instead of 64-bit x86 code.

  2. You need to fix your installation, as the installed compiler is incompatible with the installed assembler. You don't need to use either -m32 or -m64 option to compile a hello world program.

  3. The problem is that your compiler isn't compatible with your assembler. Your compiler is only capable of generating 32-bit code, but your assembler assumes 64-bit code by default. Your compiler incorrectly assumes that your assembler defaults to 32-bit and so doesn't pass the necessary option that would allow the assembler to work with 32-bit code.

  4. It means that your compiler isn't capable of generating 64-bit code.

  5. The first step of of building GCC, the compiler you're using, is to run the configure script included with the source code. This line shows how that configure script was run, including what arguments were used.

  6. Because the installed version of GCC on your computer was built to only target 32-bit. It will run on a x86_64 CPU in 32-bit mode, and, with a compatible assembler, it can generate code that will run on a x86_64 CPU in 32-bit mode.

I have no idea why your compiler and/or assembler were installed incorrectly or how to fix it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM