9

I know that LD_LIBRARY_PATH is evil and it's a good habit to avoid using it. I have a program called server.c 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 -L and -R options without setting LD_LIBRARY_PATH and it worked fine. (I noticed it won't work without setting -R option) But the compiled program kept linking to /usr/local/ssl/lib/libssl.so.0.9.8 instead of /.../libssl.so.1.0.0. Is there a work-around for this?

BTW, please correct me if I'm wrong: is it the -R option that actually "link" the shared libraries at runtime and -L option only "load" shared libraries at compile time?

Any help will be much appreciated!

Z.Zen

//////////////////////////////////////////////

Here is my Makefile:

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
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Z.Zen
  • 838
  • 1
  • 10
  • 21

2 Answers2

16

I figured out that I can include the absolute path of the specific library that I want to link to and it worked fine for me:

LD = ${RPATH} -lsocket -lnsl -lpthread ${OPENSSLDIR}/lib/libssl.so.1.0.0 \
         ${OPENSSLDIR}/lib/libcrypto.so.1.0.0

If you are using g++, Piotr Lesnicki pointed out that -l:libssl.so.1.0.0 also works. See more at the original post.

Community
  • 1
  • 1
Z.Zen
  • 838
  • 1
  • 10
  • 21
  • 2
    I find that for gcc -l: does not work, but it will not produce an error either and still tries to link to something. – jgmjgm Nov 09 '15 at 11:14
1

Do you have any links to the SSL lib? If not, can you create a link to the the desired SSL lib like

ln -s libssl.so.1.0.0 libssl.so 

in the ssl directory and try it

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Raghuram
  • 3,937
  • 2
  • 19
  • 25
  • yeah, symlink is a good way to do it but sometimes I need to link to older version of the openssl library. I want something that I can change every time I compile my program. But thanks, it works! – Z.Zen Aug 03 '10 at 02:50