title: How to link a specific version of a shared library in makefile without using LD_LIBRARY_PATH?
body: <p>I know that <a href="http://blogs.oracle.com/ali/entry/avoiding_ld_library_path_the" rel="noreferrer">LD_LIBRARY_PATH is evil</a> and it's a good habit to avoid using it.
  I have a program called <code>server.c</code> on a remote Solaris 9 server that holds two versions of openssl library (0.9.8 and 1.0.0) and I'm using gcc 3.4.6. My program need to link to 1.0.0a version. Because it's work environment, I don't have the right to modify anything in the openssl library directory. I figured out to compile my program with both <code>-L</code> and <code>-R</code> options without setting <code>LD_LIBRARY_PATH</code> and it worked fine. (I noticed it won't work without setting <code>-R</code> option) But the compiled program kept linking to <code>/usr/local/ssl/lib/libssl.so.0.9.8</code> instead of <code>/.../libssl.so.1.0.0</code>. Is there a work-around for this?</p>
  
  <p>BTW, please correct me if I'm wrong: is it the <code>-R</code> option that actually "link" the shared libraries at runtime and <code>-L</code> option only "load" shared libraries at compile time?</p>
  
  <p>Any help will be much appreciated!</p>
  
  <p>Z.Zen</p>
  
  <p>//////////////////////////////////////////////</p>
  
  <p>Here is my <strong>Makefile</strong>:</p>
  
  <pre><code>CC = gcc
  OPENSSLDIR = /usr/local/ssl
  CFLAGS = -g -Wall -W -I${OPENSSLDIR}/include -O2 -D_REENTRANT -D__EXTENSIONS__ 
  
  RPATH = -R${OPENSSLDIR}/lib
  LD = ${RPATH} -L${OPENSSLDIR}/lib -lssl -lcrypto -lsocket -lnsl -lpthread
  
  OBJS = common.o
  
  PROGS = server
  
  all: ${PROGS}
  
  server: server.o ${OBJS}
          ${CC} server.o ${OBJS} -o server ${LD}
  
  
  clean:;
          ${RM} ${PROGS} *.ln *.BAK *.bak *.o
  </code></pre>