title: linking problem: i386:x86-64 architecture of input file *.o is incompatible with i386 output
body: <p>I got a problem in linking when I moved my osdev to linux where it worked previously on gcc 3.5.* and binutils 2.18 (compiled to output x86_64-elf) running under cygwin.<br/><br/>
  Here are the infos:<br/><br/>
  <strong>gcc -v</strong><br/></p>
  
  <pre><code>
  Using built-in specs.
  Target: i686-linux-gnu
  Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
  Thread model: posix
  gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) 
  </code></pre>
  
  <p><br/>
  <br/>
  <strong>ld -v</strong><br/><pre>
  <code>
  GNU ld (GNU Binutils for Ubuntu) 2.20.51-system.20100908<br/>
  </code><br/><br/></pre></p>
  
  <p>part of <strong>ld -help</strong><br/>
  <pre><code>
  ....<br/>
  ld: supported targets: elf32-i386 a.out-i386-linux pei-i386 elf32-little elf32-big elf64-x86-64 pei-x86-64 elf64-l1om elf64-little elf64-big plugin srec symbolsrec verilog tekhex binary ihex trad-core<br/>
  ....
  </pre></code><br/><br/>
  <br/><br/>
  <strong>The code:</strong><br/>
  <br/>
  <strong>main.c</strong><br/><pre>
  <code>
  void main(){<br/>
      /**some code here**/<br/>
  }
  </code></pre><br/><br/>
  <strong>start.asm</strong><br/><pre>
  <code>
  [bits 64]<br/>
  global start<br/>
  extern main<br/>
  start:<br/>
  call main</code></pre><br/><br/>
  <strong>link.ld</strong><br/>
  <pre><code>
  OUTPUT_FORMAT(elf64-x86-64);<br/>
  offset = 0x1000000;<br/>
  ENTRY(start);<br/>
  SECTIONS{<br/>
      . = offset;<br/>
      .text : AT(ADDR(.text) - offset){<br/>
          _code = .;<br/>
          *(.text)<br/>
          <em>(.rodata</em>)<br/>
          . = ALIGN(4096);}<br/>
     .data : AT(ADDR(.data) - offset){<br/>
          _data = .;<br/>
          *(.data)<br/>
          . = ALIGN(4096);}<br/>
     .bss : AT(ADDR(.bss) - offset){<br/>
         _bss = .;<br/>
         *(.bss)<br/>
         *(COMMON)<br/>
         . = ALIGN(4096);}<br/>
     _end = .;<br/>
     /DISCARD/ :<br/>
     {*(.comment)}<br/>
  }</code></pre><br/><br/>
  <strong>build.sh</strong><br/>
  <pre><code>
  nasm -f elf64 -o start.o start.asm<br/>
  echo .<br/>
  echo .<br/>
  echo .<br/>
  gcc -m64 -ffreestanding -nostdlib -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -c -o main.o main.c<br/>
  echo .<br/>
  echo .<br/>
  echo .<br/>
  ld -nostdlib -nodefaultlibs -T link.ld -o out.elf start.o main.o<br/>
  </code></pre><br/><br><br>
  <strong>terminal output</strong><br/>
  <pre><code>
  .<br/>
  .<br/>
  .<br/>
  .<br/>
  .<br/>
  .<br/>
  ld: i386:x86-64 architecture of input file 'start.o' is incompatible with i386 output
  <br/>ld: i386:x86-64 architecture of input file 'main.o' is incompatible with i386 output
  </code></pre><br/><br/>
  I don't understand why it displays 'incompatible with i386 output' when there's OUTPUT_FORMAT(elf64-x86-64); in my linker script specifying the targeted output..</p>