编译C文件时不支持X86-64指令集的错误 [英] Unsupported x86-64 instruction set error when compiling C file

查看:1349
本文介绍了编译C文件时不支持X86-64指令集的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跟随的链接。

当我坐下来,我开始做一个test.c的文件中的一部分,我尝试运行的第一个编译行。

When I get down to the part where I start making a test.c file, I try to run the first compilation line.

gcc -c -g -Os -march=i686 -ffreestanding -Wall -Werror test.c -o test.o

下面是 test.c以

__asm__(".code16\n");
__asm__("jmpl $0x0000, $main\n");

void main() {
}

在我所说的第一个编译行,那就说明我这个错误。

When I call the first compilation line, it shows me this error.

test.c:1:0: error: CPU you selected does not support x86-64 instruction set
 __asm__(".code16\n");
 ^

谁能告诉我为什么发生这种情况?如果可能的话,如何解决它?

Can anyone tell me why this is happening? And if possible, how to fix it?

我正在运行Ubuntu桌面版x64,感谢你在您的帮助。

I am running Ubuntu Desktop x64, thank you in advance for your help.

编辑:

我已经改变了第一个编译行:

I have changed the first compilation line to:

gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o

和它似乎很好地工作。然而,有两行所给我的麻烦。

And it seems to work fine. However, there are two more lines that are giving me trouble.

ld -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o

objcopy -O binary test.elf test.bin

第一个抛出我的错误。

The first one throws me the error of.

ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output

也正因为如此,我还没有试过编译的最后一行。

And because of this, I have not tried the final line of compilation.

下面是code为test.ld文件。

Here is the code for the test.ld file.

ENTRY(main);
SECTIONS
{
    . = 0x7C00;
    .text : AT(0x7C00)
    {
        *(.text);
    }
    .sig : AT(0x7DFE)
    {
        SHORT(0xaa55);
    }
} 

这是如何解决这一问题有什么建议?

Any suggestions on how to fix this?

推荐答案

供应 -m32 而不是 -march = i686的

这篇关于编译C文件时不支持X86-64指令集的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆