我正在尝试按照此链接中的教程进行操作。
当我开始制作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
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句