[英]Unsupported x86-64 instruction set error when compiling C file
我正在嘗試按照此鏈接中的教程。
當我開始編寫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
。
實際上添加 -m32
你可以保持-march = i686 ...
gcc -c -g -Os -march=i686 -m32 -ffreestanding -Wall -Werror test.c -o test.o
作品
gcc -c -g -Os -march=i686 -m16 -ffreestanding -Wall -Werror test.c -o test.o
作品
gcc -c -g -Os -march=i686 -m64 -ffreestanding -Wall -Werror test.c -o test.o
失敗了;
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.