title: `bash: ./a.out: No such file or directory` on running executable produced by `ld`
body: <p>Here is a Hello World code in C:</p>
  
  <pre><code>// a.c
  #include &lt;stdio.h&gt;
  
  int main() {
      printf("Hello world\n");
      return 0;
  }
  </code></pre>
  
  <p>I compile it as <code>gcc a.c</code>, which produces <code>a.out</code> as expected and <code>./a.out</code> prints <code>Hello world</code>... as expected.</p>
  
  <p>Now if I do the compile and link separately: 
  <code>gcc -c a.c; ld -lc a.o</code>, it run the <code>a.out</code> produced as <code>./a.out</code> I get the message:</p>
  
  <pre><code>bash: ./a.out: No such file or directory
  </code></pre>
  
  <p>I Googled that error and it seems that happens when the executable produced is a 32-bit ELF and the machine architecture is 64-bit.</p>
  
  <p>I'm running a 64-bit machine and running <code>file a.out</code> gives:</p>
  
  <pre><code>a.out: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
  </code></pre>
  
  <p>Why does this happen?</p>
  
  <p>EDIT:</p>
  
  <p>Output of <code>uname -m</code></p>
  
  <pre><code>$ uname -m
  x86_64
  </code></pre>
  
  <p>Output of <code>ldd a.out</code></p>
  
  <pre><code>$ ldd a.out
      linux-vdso.so.1 =&gt;  (0x00007ffeeedfb000)
      libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa13a7b8000)
      /lib64/ld-linux-x86-64.so.2 (0x00007fa13abab000)
  </code></pre>
  
  <p><code>gcc a.c</code> produces <code>a.out</code> which runs correctly.</p>