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

时间:2022-09-01 10:22:20

I am trying to compile a helloworld.c code

我正在尝试编译helloworld.c代码

#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.

在Linux机器上。下面是机器的uname-结果,表明机器是64位。

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:

在运行gcc命令时,我收到以下错误:

 [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:

这是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.

仔细观察上面的内容,我确实看到目标是i686(我不确定是32位还是64位)。我的强烈猜测是它是32位。我用Google搜索了一段时间,结果表明问题可能出在64位机器上的32位编译器上。但是,一些结果还指出使用-m32和-m64选项来执行成功的编译运行。

I did a gcc run with -m64 and it resulted in the below error.

我用-m64执行了gcc运行,结果出现以下错误。

 [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.

1)目标中的i686代表32位还是64位机器?我怎样才能做出这种区分?通常i386指的是32位和x86_64到64位。

2) How can I run a simple helloworld.c in my case? When, why and how do I use -m32 and -64 options?

2)如何在我的案例中运行一个简单的helloworld.c?何时,为什么以及如何使用-m32和-64选项?

3) Does this have something to do with the assembler or compiler?

3)这是否与汇编器或编译器有关?

4) What does "sorry, unimplemented: 64-bit mode not compiled in" imply?

4)“抱歉,未实现:64位模式未编译”是什么意思?

5) What is the meaning of "Configured with: ../gcc-4.2.4/configure --prefix=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local"?

5)“配置为:../ 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?

6)当我运行64位机器时,为什么目标机器不是gcc下的x86_64?

I will really appreciate someone taking time and answering my above questions. Thanks in advance!

我真的很感激有人花时间回答我的上述问题。提前致谢!

1 个解决方案

#1


2  

  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.

    i686是用于Pentium Pro和Pentium II处理器的Intel CPU架构的参考。它还意味着目标是32位x86代码而不是64位x86代码。

  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.

    您需要修复安装,因为安装的编译器与安装的汇编程序不兼容。您不需要使用-m32或-m64选项来编译hello world程序。

  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.

    问题是您的编译器与汇编程序不兼容。您的编译器只能生成32位代码,但默认情况下汇编程序假定为64位代码。您的编译器错误地假定您的汇编程序默认为32位,因此不会传递允许汇编程序使用32位代码的必要选项。

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

    这意味着您的编译器无法生成64位代码。

  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.

    构建GCC(您正在使用的编译器)的第一步是运行源代码中包含的configure脚本。此行显示了如何运行配置脚本,包括使用了哪些参数。

  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.

    因为您计算机上安装的GCC版本仅针对32位。它将在32位模式下运行在x86_64 CPU上,并且通过兼容的汇编程序,它可以生成将在32位模式下在x86_64 CPU上运行的代码。

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

我不知道为什么你的编译器和/或汇编程序安装不正确或如何解决它。

#1


2  

  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.

    i686是用于Pentium Pro和Pentium II处理器的Intel CPU架构的参考。它还意味着目标是32位x86代码而不是64位x86代码。

  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.

    您需要修复安装,因为安装的编译器与安装的汇编程序不兼容。您不需要使用-m32或-m64选项来编译hello world程序。

  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.

    问题是您的编译器与汇编程序不兼容。您的编译器只能生成32位代码,但默认情况下汇编程序假定为64位代码。您的编译器错误地假定您的汇编程序默认为32位,因此不会传递允许汇编程序使用32位代码的必要选项。

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

    这意味着您的编译器无法生成64位代码。

  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.

    构建GCC(您正在使用的编译器)的第一步是运行源代码中包含的configure脚本。此行显示了如何运行配置脚本,包括使用了哪些参数。

  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.

    因为您计算机上安装的GCC版本仅针对32位。它将在32位模式下运行在x86_64 CPU上,并且通过兼容的汇编程序,它可以生成将在32位模式下在x86_64 CPU上运行的代码。

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

我不知道为什么你的编译器和/或汇编程序安装不正确或如何解决它。