title: LD_LIBRARY_PATH does not work
body: <p>I'm trying to compile a demo which uses zlib, and I think I've done correct set up for LD_LIBRARY_PATH but it does not work with -lz flag, would you please help me find what's the problem?</p>
  
  <pre><code>lisanhu@lisanhu-XPS-15-9550:kseq$ echo $LD_LIBRARY_PATH 
  /home/lisanhu/mine/repos/zlib/output/lib
  lisanhu@lisanhu-XPS-15-9550:kseq$ make
  gcc -g -O2 kseq_test.c -o kseq_test -lz
  /usr/bin/ld: cannot find -lz
  collect2: error: ld returned 1 exit status
  Makefile:3: recipe for target 'all' failed
  make: *** [all] Error 1
  lisanhu@lisanhu-XPS-15-9550:kseq$ gcc -static -o kseq_test kseq_test.o -lz -L/home/lisanhu/mine/repos/zlib/output/lib
  lisanhu@lisanhu-XPS-15-9550:kseq$
  </code></pre>
  
  <p>The problem is that if I use <code>-L</code> to force searching the folder, it works, if I put that folder in LD_LIBRARY_PATH, it doesn't work. I'm pretty sure I've used <code>export LD_LIBRARY_PATH</code> but it still doesn't work. </p>
  
  <p>This is annoying because if I need to compile someone else's code that needs it, it's easier to set up a environment variable to search for the libraries.</p>
  
  <p>--------------Update------------</p>
  
  <p>On another server I tried this and it works smoothly</p>
  
  <pre><code>[lisanhu@farber tmp]$ export LD_LIBRARY_PATH=/home/1677/mine/repos/zlib/zlib-1.2.8
  [lisanhu@farber tmp]$ ls
  gmon.out  kseq.h  kseq.tar  kseq_test  kseq_test.c  Makefile
  [lisanhu@farber tmp]$ make
  cc -g -O2 kseq_test.c -o kseq_test -lz
  [lisanhu@farber tmp]$ ldd kseq_test
      linux-vdso.so.1 =&gt;  (0x00007fffb01a6000)
      libz.so.1 =&gt; /home/1677/mine/repos/zlib/zlib-1.2.8/libz.so.1 (0x00007f9556c83000)
      libc.so.6 =&gt; /lib64/libc.so.6 (0x00000031fa400000)
      /lib64/ld-linux-x86-64.so.2 (0x00000031fa000000)
  [lisanhu@farber tmp]$ 
  </code></pre>
  
  <p>So my configuration may be correct? Any ideas?
  I've tried it on my laptops with Ubuntu 16.04 and Fedora 25, updated to stable on Feb. 16, 2017. The server I can only tell it's not newly updated. I'm wondering whether there's problem with the newest gcc?</p>
  
  <p>--------------Update------------</p>
  
  <p>I may know what causes the problem. The error message is <code>cannot find -lz</code>. It seems to treat <code>-lz</code> as a single file. I find there's both <code>-l</code> and <code>-z</code> flag in the usage of <code>ld</code> while it may convert <code>-lz</code> to something like that and find we don't have a parameter for both of the flags and then combine them together as a single file parameter?
  Not fully sure about my inference but does anyone have any idea of how to handle this case?</p>
  
  <p>--------------Update------------</p>
  
  <p>Full Makefile</p>
  
  <pre><code>all:kseq.h kseq_test.c
          $(CC) -g -O2 kseq_test.c -o kseq_test -lz
  
  clean:
          rm -f *.o
  </code></pre>
  
  <p>--------------Update------------</p>
  
  <p>The 3rd section may not be a valid explanation because after appending -v to cc, I've found -lz is successfully passed to the linker</p>