我正在尝试按照 this 中的教程进行操作链接。
当我开始制作 test.c 文件的部分时,我尝试运行第一行编译。
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() {
}
当我调用第一个编译行时,它向我显示此错误。
test.c:1:0: error: CPU you selected does not support x86-64 instruction set
__asm__(".code16\n");
^
谁能告诉我为什么会这样?如果可能,如何解决?
我正在运行 Ubuntu Desktop x64,在此先感谢您的帮助。
编辑:
我已将第一行编译更改为:
gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o
它似乎工作正常。但是,还有两行给我带来了麻烦。
ld -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o
和
objcopy -O binary test.elf test.bin
第一个给我的错误是。
ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output
也正因如此,我还没有尝试编译最后一行。
这是 test.ld 文件的代码。
ENTRY(main);
SECTIONS
{
. = 0x7C00;
.text : AT(0x7C00)
{
*(.text);
}
.sig : AT(0x7DFE)
{
SHORT(0xaa55);
}
}
关于如何解决这个问题有什么建议吗?
最佳答案
提供 -m32
而不是 -march=i686
。
关于c - 编译C文件时出现Unsupported x86-64 instruction set错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27679693/