运行时有多个版本的库文件怎么办?
2015-10-18 17:34
267 查看
1. The linker is able to accept filenames too
From
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename,
ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
I noticed that older versions do not support it, so check
on your system.
You could also link to the file mentioning its full name
编译完成后可以使用以下命令查看路径是否设置成功了
[plain]
view plaincopy
$ readelf -dl evh
看到类似下面的信息则是路径设置成功了
[plain]
view plaincopy
0x000000000000000f (RPATH) Library rpath: [/usr/local/lib/:/data1/thd/jsoncpp/lib/:/data1/thd/leveldb/lib/:/data1/tools/boost_1_53_0/stage/lib/]
另外以下命令可以查看可执行文件的依赖库
[plain]
view plaincopy
$ ldd a.out
可明确的知道需要那些依赖库,以及哪些依赖库找不到
2. -Wl,-rpath, 用于指定程序运行时查找动态链接库的路径,多个路径是使用冒号隔
4000
开。这样就不用添加路径到 /etc/ld.so.conf 文件中了,在需要多个so版本共存时很有用
3. 命令
I don’t know about the specific application, but sometimes it’s indeed necessary to set in a small wrapper script to the application an additional LD_LIBRARY_PATH before starting the application. Which library will be used can be checked by:
Code:
Another variable you can try is LD_PRELOAD if it’s still using the wrong libraries.
Another approach to make it more happen automatically for you: install the new libraries in a different location (i.e. go back to the initial setup of the libraries in your system). Then you can change the rpath to the libraries directly in the
compiled application by the tool:
Code:
which can change the written rpath to libraries during the link step of the application. You can check the binary whether it was changed correctly by:
Code:
If there was no rpath compiled in, you can also add the appropriate option already to the link step.
gcc app.o -l:libmy.so.1 -o app
From
man ld:
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename,
ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
I noticed that older versions do not support it, so check
man ld
-lor
--libraryoption
on your system.
You could also link to the file mentioning its full name
gcc app.o /mylibpath/libmy.so.1 -o app
[plain]
view plaincopy
$ readelf -dl evh
看到类似下面的信息则是路径设置成功了
[plain]
view plaincopy
0x000000000000000f (RPATH) Library rpath: [/usr/local/lib/:/data1/thd/jsoncpp/lib/:/data1/thd/leveldb/lib/:/data1/tools/boost_1_53_0/stage/lib/]
另外以下命令可以查看可执行文件的依赖库
[plain]
view plaincopy
$ ldd a.out
可明确的知道需要那些依赖库,以及哪些依赖库找不到
2. -Wl,-rpath, 用于指定程序运行时查找动态链接库的路径,多个路径是使用冒号隔
4000
开。这样就不用添加路径到 /etc/ld.so.conf 文件中了,在需要多个so版本共存时很有用
3. 命令
I don’t know about the specific application, but sometimes it’s indeed necessary to set in a small wrapper script to the application an additional LD_LIBRARY_PATH before starting the application. Which library will be used can be checked by:
Code:
$ ldd program
Another variable you can try is LD_PRELOAD if it’s still using the wrong libraries.
Another approach to make it more happen automatically for you: install the new libraries in a different location (i.e. go back to the initial setup of the libraries in your system). Then you can change the rpath to the libraries directly in the
compiled application by the tool:
Code:
$ chrpath program
which can change the written rpath to libraries during the link step of the application. You can check the binary whether it was changed correctly by:
Code:
$ readelf -d program
If there was no rpath compiled in, you can also add the appropriate option already to the link step.
相关文章推荐
- 集合框架
- ES6 的初步了解(一)
- HDU 2015 偶数求和
- 格雷码代码
- 同步异步浅析
- 黑马程序员——ObjectiveC基础——类对象和SEL类型
- linux设置-centos7防火墙配置
- 【SSH项目实战】国税协同平台-1.项目介绍
- 为Web应用增加Struts2支持
- 浅析LRU(K-V)缓存
- Bob的墙
- CentOS安装nexus(Maven仓库管理器)
- AngularJS-Controller的使用-读书笔记
- 22.Android 十分方便的滑动标签页EasySlidingTabs
- 不要让类型默默转换
- 如何正确导入Android支持库
- UIScrollView
- Remove Linked List Elements
- MDK-ARM下mini2440 Nandflash算法实现及下载设置
- NYOJ——28 大数阶乘