Unsupported x86-64 instruction set error when compiling C file

前端 未结 3 2263
清歌不尽
清歌不尽 2021-02-15 00:05

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.



        
相关标签:
3条回答
  • 2021-02-15 00:27

    in fact add -m32 you can keep -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");

    0 讨论(0)
  • 2021-02-15 00:30
    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
    
    0 讨论(0)
  • 2021-02-15 00:39

    Supply -m32 instead of -march=i686.

    0 讨论(0)
提交回复
热议问题