title: Linking a C program directly with ld fails with undefined reference to `__libc_csu_fini`
body: <p>I'm trying to compile a C program under Linux. However, out of curiosity, I'm trying to execute some steps by hand: I use:</p>
  
  <ul>
  <li>the gcc frontend to produce assembler code</li>
  <li>then run the GNU assembler to get an object file</li>
  <li>and then link it with the C runtime to get a working executable.</li>
  </ul>
  
  <p>Now I'm stuck with the linking part.</p>
  
  <p>The program is a very basic "Hello world":</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
     printf("Hello\n");
     return 0;
  }
  </code></pre>
  
  <p>I use the following command to produce the assembly code:</p>
  
  <pre><code>gcc hello.c -S -masm=intel
  </code></pre>
  
  <p>I'm telling gcc to quit after compiling and dump the assembly code with Intel syntax.</p>
  
  <p>Then I use th GNU assembler to produce the object file:</p>
  
  <pre><code>as -o hello.o hello.s
  </code></pre>
  
  <p>Then I try using ld to produce the final executable:</p>
  
  <pre><code>ld hello.o /usr/lib/libc.so /usr/lib/crt1.o -o hello
  </code></pre>
  
  <p>But I keep getting the following error message:</p>
  
  <pre><code>/usr/lib/crt1.o: In function `_start':
  (.text+0xc): undefined reference to `__libc_csu_fini'
  /usr/lib/crt1.o: In function `_start':
  (.text+0x11): undefined reference to `__libc_csu_init'
  </code></pre>
  
  <p>The symbols <code>__libc_csu_fini/init</code> seem to be a part of glibc, but I can't find them anywhere! I tried linking against libc statically (against <code>/usr/lib/libc.a</code>) with the same result.</p>
  
  <p>What could the problem be?</p>