title: What causes "x.asm:(.text+0xd): undefined reference to `y'"?
body: <p>For a long time I had not programmed with C and Assembler (about 2 years). Now I have decided to start again but I would like to do something much more complicated. I thought about creating a simple kernel. Now I found this source code on the internet:</p>
  
  <p>boot.asm:</p>
  
  <pre><code>global loader
  extern kernel_main
  MAGIC equ 0xbad
  FLAGS equ 0x3
  CHECKSUM equ -(MAGIC+FLAGS)
  
  section .text
  align 4
  dd MAGIC
  dd FLAGS
  dd CHECKSUM
  
  loader:
  call kernel_main
  cli
  
  quit:
  hlt
  jmp quit
  </code></pre>
  
  <p>kernel.c:</p>
  
  <pre><code>void print(char *text) {
      char *memory = (char*)0xb8000;
      while(*text) {
          *memory++ = *text++;
          *memory++ = 0x3;
      }
  }
  
  void kernel_main() {
      print("My cat sometimes smells like cafe. I love it.");
  }
  </code></pre>
  
  <p>linker.ld:</p>
  
  <pre><code>ENTRY(loader)
  SECTIONS {
        . = 0x100000;
        .text : { *(.text) }
  }
  </code></pre>
  
  <p>Note: I compiled the C file with "GCC" and the Assembler file with "NASM".</p>
  
  <p>If I try this command:</p>
  
  <pre><code>ld -T linker.ld -elf_i386 -o final.bin boot.o kernel.o
  </code></pre>
  
  <p>It says: "boot.asm:(.text+0xd): undefined reference to `kernel_main'".
  How can I fix this?
  Im working on windows and do not want to run a VM with Linux or anything. Thanks in advance!</p>
  
  <p>Edit:
  This is my GCC command: </p>
  
  <pre><code>gcc -m32 -o kernel.o srckernel.c -nostdlib -nostartfiles -nodefaultlibs
  </code></pre>
  
  <p>This is my NASM command:</p>
  
  <pre><code>nasm -f elf32 -o boot.o boot.asm
  </code></pre>