当前位置: 技术问答>linux和unix
Unix上动态库链接问题
来源: 互联网 发布时间:2016-10-12
本文导语: 本帖最后由 ankeran 于 2010-11-01 18:45:09 编辑 在HP上编译出Openssl的库:libcrypto.so.1.0.0,放置在:/export/home/mine/dbserver/r9.2_development/Openssl/lib64/hp下。 编译使用此库的source: cc +DD64 -I/export/home/tt/openssl/include -c aes_test.c cc ...
编译使用此库的source:
cc +DD64 -I/export/home/tt/openssl/include -c aes_test.c
cc -o aes_test aes_test.o +DD64 -I/export/home/tt/openssl/include -L/export/home/mine/dbserver/r9.2_development/Openssl/lib64/hp -lcrypto
动态库相关环境变量的设定:
SHLIB_PATH=/export/home/mine/dbserver/r9.2_development/Openssl/lib64/hp
LD_LIBRARY_PATH=/export/home/mine/dbserver/r9.2_development/Openssl/lib64/hp
可编译出的执行文件aes_test并不是链接libcrypto.so.1.0.0这个文件。而是链接上了系统已有的openssl库文件libcrypto.so.0,具体如下:
执行ldd aes_test:
libcrypto.so.0 => /usr/lib/hpux64/libcrypto.so.0
libc.so.1 => /usr/lib/hpux64/libc.so.1
libdl.so.1 => /usr/lib/hpux64/libdl.so.1
libc.so.1 => /usr/lib/hpux64/libc.so.1
libdl.so.1 => /usr/lib/hpux64/libdl.so.1
执行chatr aes_test:
aes_test:
64-bit ELF executable
shared library dynamic path search:
LD_LIBRARY_PATH enabled first
SHLIB_PATH enabled second
embedded path enabled third /export/home/mine/dbserver/r9.2_development/Openssl/lib64/hp:/usr/lib
/hpux64:/opt/langtools/lib/hpux64
shared library list:
libcrypto.so.0
libc.so.1
shared library binding:
deferred
global hash table disabled
global hash table size 1103
shared library mapped private disabled
shared library segment merging disabled
shared vtable support disabled
explicit unloading disabled
linkage table protection disabled
segments:
index type address flags size
8 text 4000000000000000 z---c- D (default)
9 data 6000000000000000 ---m-- D (default)
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation for dynamic segments disabled
nulptr dereferences trap disabled
address space model: default
caliper dynamic instrumentation disabled
问题:
1.为何系统会自动加版本号,如何加的?
2.如何让程序正确链接到libcrypto.so.1.0.0?
|
格式错了...重来..
[13:26:47 +0000 root@dev-caik ~]# ldd /usr/bin/which
linux-gate.so.1 => (0x00110000)
libc.so.6 => /lib/libc.so.6 (0x00874000)
/lib/ld-linux.so.2 (0x00855000)
[13:26:49 +0000 root@dev-caik ~]# LD_LIBRARY_PATH=/root ldd /usr/bin/which
linux-gate.so.1 => (0x00110000)
libc.so.6 => /root/libc.so.6 (0x00874000)
/lib/ld-linux.so.2 (0x00855000)