title: Unrecognised emulation mode: elf_i386 on MinGW32
body: <p>I'm trying to make a kernel, and I cannot link the <em>C</em> output with the assembly. The <code>ld</code>. I'm getting the error:</p>
  
  <blockquote>
    <p>unrecognized emulation mode: elf_i386</p>
  </blockquote>
  
  <p>I'm using Windows 10 professional with the MinGW32 and MSYS. The code I am using:</p>
  
  <p><strong>link.ld</strong></p>
  
  <pre><code>/*
  *  link.ld
  */
  OUTPUT_FORMAT(elf32-i386)
  ENTRY(start)
  SECTIONS
   {
     . = 0x100000;
     .text : { *(.text) }
     .data : { *(.data) }
     .bss  : { *(.bss)  }
   }
  </code></pre>
  
  <p><strong>kernel.c</strong></p>
  
  <pre><code>/*
  *  kernel.c
  */
  void kmain(void)
  {
      const char *str = "my first kernel";
      char *vidptr = (char*)0xb8000;  //video mem begins here.
      unsigned int i = 0;
      unsigned int j = 0;
  
      /* this loops clears the screen
      * there are 25 lines each of 80 columns; each element takes 2 bytes */
      while(j &lt; 80 * 25 * 2) {
          /* blank character */
          vidptr[j] = ' ';
          /* attribute-byte - light grey on black screen */
          vidptr[j+1] = 0x07;         
          j = j + 2;
      }
  
      j = 0;
  
      /* this loop writes the string to video memory */
      while(str[j] != '\0') {
          /* the character's ascii */
          vidptr[i] = str[j];
          /* attribute-byte: give character black bg and light grey fg */
          vidptr[i+1] = 0x07;
          ++j;
          i = i + 2;
      }
      return;
  }
  </code></pre>
  
  <p><strong>kernel.asm</strong></p>
  
  <pre><code>;;kernel.asm
  bits 32         ;nasm directive - 32 bit
  section .text
  
  global start
  extern kmain            ;kmain is defined in the c file
  
  start:
    cli           ;block interrupts
    mov esp, stack_space  ;set stack pointer
    call kmain
    hlt           ;halt the CPU
  
  section .bss
  resb 8192       ;8KB for stack
  stack_space:
  </code></pre>
  
  <p>To Compile and link I use:</p>
  
  <pre><code>nasm -f elf32 kernel.asm -o kasm.o
  gcc -m32 -c kernel.c -o kc.o
  ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o
  </code></pre>
  
  <p>I'm Using:</p>
  
  <ul>
  <li>Gcc 4.8.1</li>
  <li>Ld 2.25.1</li>
  <li>Nasm 2.11.09rc1</li>
  </ul>
  
  <p>Why am I getting this error, and how can I fix it?</p>