title: Unsupported x86-64 instruction set error when compiling C file
body: <p>I am trying to follow the tutorials in <a href="http://www.codeproject.com/Articles/664165/Writing-a-boot-loader-in-Assembly-and-C-Part" rel="noreferrer">this</a> link.</p>
  
  <p>When I get down to the part where I start making a test.c file, I try to run the first compilation line.</p>
  
  <pre><code>gcc -c -g -Os -march=i686 -ffreestanding -Wall -Werror test.c -o test.o
  </code></pre>
  
  <p>Here is the contents of <code>test.c</code></p>
  
  <pre><code>__asm__(".code16\n");
  __asm__("jmpl $0x0000, $main\n");
  
  void main() {
  }
  </code></pre>
  
  <p>When I call the first compilation line, it shows me this error.</p>
  
  <pre><code>test.c:1:0: error: CPU you selected does not support x86-64 instruction set
   __asm__(".code16\n");
   ^
  </code></pre>
  
  <p>Can anyone tell me why this is happening? And if possible, how to fix it?</p>
  
  <p>I am running Ubuntu Desktop x64, thank you in advance for your help.</p>
  
  <p>EDIT:</p>
  
  <p>I have changed the first compilation line to:</p>
  
  <pre><code>gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o
  </code></pre>
  
  <p>And it seems to work fine. However, there are two more lines that are giving me trouble.</p>
  
  <pre><code>ld -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o
  </code></pre>
  
  <p>and</p>
  
  <pre><code>objcopy -O binary test.elf test.bin
  </code></pre>
  
  <p>The first one throws me the error of.</p>
  
  <pre><code>ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output
  </code></pre>
  
  <p>And because of this, I have not tried the final line of compilation.</p>
  
  <p>Here is the code for the test.ld file.</p>
  
  <pre><code>ENTRY(main);
  SECTIONS
  {
      . = 0x7C00;
      .text : AT(0x7C00)
      {
          *(.text);
      }
      .sig : AT(0x7DFE)
      {
          SHORT(0xaa55);
      }
  } 
  </code></pre>
  
  <p>Any suggestions on how to fix this?</p>