[英]Unsupported x86-64 instruction set error when compiling C file
I am trying to follow the tutorials in this link. 我正在尝试按照此链接中的教程。
When I get down to the part where I start making a test.c file, I try to run the first compilation line. 当我开始编写test.c文件的部分时,我尝试运行第一个编译行。
gcc -c -g -Os -march=i686 -ffreestanding -Wall -Werror test.c -o test.o
Here is the contents of test.c
这是
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?
如果可能的话,如何修复它?
I am running Ubuntu Desktop x64, thank you in advance for your help. 我正在运行Ubuntu Desktop x64,请提前感谢您的帮助。
EDIT: 编辑:
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
and 和
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. 因此,我还没有尝试最后的编译。
Here is the code for the test.ld file. 这是test.ld文件的代码。
ENTRY(main);
SECTIONS
{
. = 0x7C00;
.text : AT(0x7C00)
{
*(.text);
}
.sig : AT(0x7DFE)
{
SHORT(0xaa55);
}
}
Any suggestions on how to fix this? 对于如何解决这个问题,有任何的建议吗?
供应-m32
而不是-march=i686
。
in fact add -m32
you can keep -march=i686 ... 实际上添加
-m32
你可以保持-march = i686 ...
gcc -c -g -Os -march=i686 -m32 -ffreestanding -Wall -Werror test.c -o test.o
works 作品
gcc -c -g -Os -march=i686 -m16 -ffreestanding -Wall -Werror test.c -o test.o
works 作品
gcc -c -g -Os -march=i686 -m64 -ffreestanding -Wall -Werror test.c -o test.o
fails with ; 失败了;
test.c:1:0: error: CPU you selected does not support x86-64 instruction set asm (".code16\\n");
test.c:1:0:错误:您选择的CPU不支持x86-64指令集asm (“。code16 \\ n”);
gcc -std=c99 -c -g -Os -march=i686 -m32 -ffreestanding -Wall -Werror test.c -o test.o
ld -static -T test.ld -m elf_i386 -nostdlib --nmagic -o test.elf test.o
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.