title: MinGW Win32 + nasm: "undefined reference"
body: <p>I am currently developing an OS for learning purposes, and it's been working fine until now. Then I tried to call an assembler function, compiled with <code>nasm, -fwin32</code>, from C code, but all I got was an "undefined reference" error. I have created a small example in pure assembler, which has the same problem, but is easily understandable and way smaller:
  It includes two files:</p>
  
  <p><strong>test.asm:</strong></p>
  
  <pre><code>[bits 32]
  global _testfunc
  _testfunc:
      ret
  
  test2.asm:
  
  [bits 32]
  extern _testfunc
  global _testfunc2
  _testfunc2:
      call _testfunc
      ret
  </code></pre>
  
  <p>Here is my compiler / linker script (using windows batch files):</p>
  
  <pre><code>nasm.exe -f win32 test.asm -o test.o
  nasm.exe -f win32 test2.asm -o test2.o
  ld test.o test2.o -o output.tmp
  </code></pre>
  
  <p>This results in the error:</p>
  
  <pre><code>test2.o:test2.asm:(.text+0x1): undefined reference to `testfunc'
  </code></pre>
  
  <p>To extend the question, the same happens when the function is called from C:</p>
  
  <p><strong>test.c:</strong></p>
  
  <pre><code>extern void testfunc(void);
  void start()
  {
      testfunc();
  }
  </code></pre>
  
  <p>With this linker script:</p>
  
  <pre><code>gcc -ffreestanding -c test.c -o testc.o
  nasm.exe -f win32 test.asm -o test.o
  ld test.o testc.o -o output.tmp
  </code></pre>
  
  <p>In test.o, test2.o and testc.o, it always says <code>_testfunc</code>, so the error has nothing to do with leading underscores!</p>