title: NASM Hello World on Linux: undefined reference to `main'
body: <p>I've been following <a href="http://asm.sourceforge.net/intro/hello.html" rel="nofollow">this tutorial</a> for an intro to assembly on Linux.</p>
  
  <pre><code>section .text
  global _start ;must be declared for linker (ld)
  
  _start:
          mov edx,len     ;message length
          mov ecx,msg     ;message to write
          mov ebx,1       ;file descriptior
          mov eax,4       ;system call number (sys_write)
          int 0x80        ;call kernel
  
          mov eax,1       ;system call number (sys_exit)
          int 0x080       ;call kernel
  
  section .data
  
  msg db 'Hello, world!', 0xa     ;the string
  len equ $ - msg                 ;length of the string
  </code></pre>
  
  <p>I've then had problems compiling it. I've looked around and found (on SO) that I should compile it like this:</p>
  
  <pre><code>nasm -f elf64 hello.asm
  gcc -o hello hello.o
  </code></pre>
  
  <p>But I keep getting this error from GCC:</p>
  
  <pre><code>hello.o: In function `_start':
  hello.asm:(.text+0x0): multiple definition of `_start'
  /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
  /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
  (.text+0x20): undefined reference to `main'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>(NB: I'm running Debian Linux on a 64 bit Intel i7)</p>