title: Assembly/Linking problem with nasm and ld
body: <p>I have a sample assembly file that I compile with nasm:</p>
  
  <pre><code>nasm -f elf syscall.asm 
  </code></pre>
  
  <p>This generates a <strong>syscall.o</strong> file. I try to link it with ld:</p>
  
  <pre><code>ld -o syscall syscall.o
  </code></pre>
  
  <p>The ld command fails with the following error:</p>
  
  <pre><code>ld: i386 architecture of input file `syscall.o' is incompatible with i386:x86-64 output
  </code></pre>
  
  <p>However, if I do</p>
  
  <pre><code>ld -o syscall syscall.o -melf_i386
  </code></pre>
  
  <p>the command succeeds and I get a <strong>syscall</strong> executable. </p>
  
  <p>Figuring out that nasm is not generating object code in x86-64 format I added "BITS 64" directive to the beginning of the syscall.asm file.</p>
  
  <p>Then attempting to assemble syscall.asm with nasm gave the following error:</p>
  
  <pre><code>error: elf output format does not support 64-bit code
  </code></pre>
  
  <p>That seems strange because doing "file /usr/bin/nasm" on my terminal gives:</p>
  
  <pre><code>/usr/bin/nasm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
  </code></pre>
  
  <p>My 64-bit Fedora Core 11 has the latest version of nasm installed and my CPU is Intel Core 2 Duo E7200.</p>
  
  <p>[EDIT]</p>
  
  <p>My question is how do I get nasm to emit object files that is compatible with i386:x86-64.</p>