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?
我知道LD_LIBRARY_PATH是邪恶的,它是避免使用它的好习惯。我有一个程序叫做服务器。在一个远程Solaris 9服务器上,它拥有两个版本的openssl库(0.9.8和1.0.0),而我使用的是gcc 3.4.6。我的程序需要链接到1.0.0a版本。因为它是工作环境,所以我没有权限在openssl库目录中修改任何东西。我找到了在不设置LD_LIBRARY_PATH的情况下使用-L和-R选项编译我的程序,并且它运行良好。(我注意到它不会在没有设置-R选项的情况下工作),但是编译后的程序会链接到/usr/local/ssl/lib/libssl.so.0.9.8而不是/…/ libssl.1.0.0。这有解决办法吗?
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?
顺便说一下,如果我错了,请纠正我:它是-R选项,实际上是在运行时“链接”共享库,而-L选项只在编译时“加载”共享库吗?
Any help will be much appreciated!
非常感谢您的帮助!
Z.Zen
Z.Zen
//////////////////////////////////////////////
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Here is my Makefile:
这是我的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
2 个解决方案
#1
15
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.
如果使用g++, Piotr Lesnicki指出-l: libssl.1.0.0也有效。更多详情请见原文。
#2
1
Do you have any links to the SSL lib? If not, can you create a link to the the desired SSL lib like
你有SSL lib的链接吗?如果没有,您可以创建一个到所需的SSL lib的链接。
ln -s libssl.so.1.0.0 libssl.so
in the ssl directory and try it
在ssl目录中并尝试它。
#1
15
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.
如果使用g++, Piotr Lesnicki指出-l: libssl.1.0.0也有效。更多详情请见原文。
#2
1
Do you have any links to the SSL lib? If not, can you create a link to the the desired SSL lib like
你有SSL lib的链接吗?如果没有,您可以创建一个到所需的SSL lib的链接。
ln -s libssl.so.1.0.0 libssl.so
in the ssl directory and try it
在ssl目录中并尝试它。