title: Why does the order of '-l' option in gcc matter?
body: <p>I am trying to compile a program which uses <a href="http://udis86.sourceforge.net/" rel="noreferrer">udis86</a> library. Actually I am using an example program given in the <a href="http://udis86.sourceforge.net/manual/manual.html#id486176" rel="noreferrer">user-manual</a> of the library. But while compiling, it gives error. The errors I get are: </p>
  
  <pre><code>example.c:(.text+0x7): undefined reference to 'ud_init'
  example.c:(.text+0x7): undefined reference to 'ud_set_input_file'
  .
  .
  example.c:(.text+0x7): undefined reference to 'ud_insn_asm'
  </code></pre>
  
  <p>The command I am using is:</p>
  
  <pre><code>$ gcc -ludis86 example.c -o example 
  </code></pre>
  
  <p>as instructed in the user-manual.</p>
  
  <p>Clearly, linker is not able to link libudis library. But if I change my command to:</p>
  
  <pre><code>$ gcc example.c -ludis86 -o example 
  </code></pre>
  
  <p>It starts working. So can please someone explain what is the problem with the first command? </p>