title: Linux: controlling where `ld` searches for .o object files?
body: <p>Ok, this is the situation: I'm trying to use some older software: works fine on Ubuntu Lucid, fails on Natty. </p>
  
  <p>So, I <code>strace</code>d around a bit, and it turns out that this software calls <code>ld</code>, and <code>ld</code> eventually fails with: </p>
  
  <pre><code>.../ld: crt1.o: No such file: No such file or directory
  </code></pre>
  
  <p>... yes, the old <a href="https://stackoverflow.com/questions/91576/crti-o-file-missing">crti.o file missing</a> error :) However, I'd like to ask the question in more general terms...</p>
  
  <p>The thing is, this is 'standalone' (older) <code>ld</code> here, and when I run <code>.../ld -verbose | less</code>, I get: </p>
  
  <pre><code>...
  SEARCH_DIR("/usr/local/lib"); 
  SEARCH_DIR("/lib"); 
  SEARCH_DIR("/usr/lib");
  ...
  </code></pre>
  
  <p>Now, the thing is that:</p>
  
  <ul>
  <li>On Lucid, <code>crt1.o</code> is in <code>/usr/lib/crt1.o</code></li>
  <li>On Natty, <code>crt1.o</code> is in <code>/usr/lib/i386-linux-gnu/crt1.o</code></li>
  </ul>
  
  <p>... so no surprise why <code>crt1.o</code> cannot be found, I guess. It seems, all I have to do, is tell <code>ld</code> to look for <code>crt1.o</code> in <code>/usr/lib/i386-linux-gnu</code>, but how do I do that? </p>
  
  <p>I thought I could use the <code>-L</code> option, but <code>man ld</code> says: </p>
  
  <pre><code>to link a file "hello.o":
  
      ld -o &lt;output&gt; /lib/crt0.o hello.o -lc
  
    This tells ld to produce a file called output as the result of linking
    the file "/lib/crt0.o" with "hello.o" and the library "libc.a", which
    will come from the standard search directories. 
  ...
  
  -L searchdir
  --library-path=searchdir
    Add path searchdir to the list of paths that ld will search for
    archive libraries and ld control scripts.
  </code></pre>
  
  <p>... meaning, '<code>-L</code>' would influence where we look for "<code>libc.a</code>" (in man example) - but not for the object files. </p>
  
  <p>I would actually prefer an environment variable for this, but I tried both <code>LD_PRELOAD_PATH</code> and <code>LD_LIBRARY_PATH</code> to no avail (I guess, those are related to "shared objects", and these <code>.o</code> files aren't one of those).  </p>
  
  <p>Does anyone know if there is an environment variable (preferably - or if not, command line option to <code>ld</code>) that would control where <code>ld</code> searches for <code>.o</code> object files? </p>
  
  <p>As a note, I guess I could just symlink <code>/usr/lib/i386-linux-gnu/crt1.o</code> in <code>/usr/lib/</code>, but I'd rather use an environment variable, if it exists... If not, are there any other possible solutions to this? </p>
  
  <p>Thank in advance for any answers,<br>
  Cheers!</p>
  
  <p>EDIT: possibly relevant: <a href="http://gcc.gnu.org/ml/gcc/2004-01/msg00521.html" rel="noreferrer">Daniel Kegel - --with-sysroot newbie troubles: "ld: cannot open crt1.o"</a></p>