title: Linking to X11 under Ubuntu
body: <p>I have a Hello, World C program for X11 downloaded from somewhere. It compiles, but doesn't link properly.</p>
  
  <p>The 32-bit Ubuntu version runs in VM VirtualBox under Windows 7. The compile and link command I use (one of many variations I tried) is:</p>
  
  <pre><code>gcc -L/usr/lib/i386-linux-gnu -lX11 hellowin.c
  </code></pre>
  
  <p>Apparently, that is the correct location, as 'locate libX11' gives me:</p>
  
  <pre><code>/usr/lib/i386-linux-gnu/libX11.a
  </code></pre>
  
  <p>amongst other such files (mostly .so ones). The errors I get are like this:</p>
  
  <pre><code>....undefined reference to 'XOpenDisplay'
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Edit: It now works if I leave out -L and move the -l to after the file as suggested. Eg:</p>
  
  <pre><code>gcc hellowin.o -lX11
  </code></pre>
  
  <p>or specifying the library directly, but this only works with .so, not .a:</p>
  
  <pre><code>gcc hellowin.o /usr/lib/i386-linux-gnu/libX11.so
  </code></pre>
  
  <p>(The build instructions with the Hello, World source used -L and -l, and they were both placed before the object file name.)</p>