静态链接到动态库。 glibc
所以。 我遇到一个问题,一台机器上有两个版本的 GCC。
3.4.6 和 4.1
这是由于新软件的一些依赖性问题。 (需要 glibc 4.1)
当我将这个新软件与 4.1 库链接时,它链接得很好。 但是,当执行软件时,它找不到该库,因为它正在我的 LD_LIBRARY_PATH 中查找 3.4.6。 如果我将 LD_LIBRARY_PATH 设置为 4.1 库,它会炸毁 shell,并杀死其他东西,因为 3.4.6 库用于此目的。
22.
有什么方法可以在链接时提供该共享库的绝对路径而不使用 LD_LIBRARY_PATH 吗?
这样我就有希望拥有两个版本,但对于这个特定的应用程序只使用 4.1?
So. I have a problem where I have two versions of GCC on a machine.
3.4.6 and 4.1
This is due to some dependency issues with a new piece of software. (requires glibc 4.1)
When I go to link this new software with the 4.1 libraries it links fine. However, when it comes to executing the software it can't find the library, because it is looking at 3.4.6 in my LD_LIBRARY_PATH. If I set LD_LIBRARY_PATH to the 4.1 lib it blows up the shell,among killing other things, because the 3.4.6 libraries are used for that.
Its a bit of a catch 22.
Is there any way that at link time I can give an absolute path to that shared library without using the LD_LIBRARY_PATH?
This way I can hopefully have both versions, but only use 4.1 for this specific application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的意思是程序启动时使用的绝对路径,并且在查找库时首选该绝对路径? rpath 就是这样。 它将覆盖默认搜索路径和 LD_LIBRARY_PATH 中设置的内容。 只需告诉 gcc 将其传递给链接器即可:
您可以让它向您显示搜索处理(使用
help
使其为您提供更多选项):You mean an absolute path that's used when the program is started and that's favored when looking for libraries?
rpath
is exactly that. It will overwrite the default search path and stuff set in LD_LIBRARY_PATH. Just tell gcc to pass it through to the linker:You can make it show you the search processing (use
help
to make it give you more options):并不是您问题的真正答案,而是替代解决方案:
您应该能够通过将新的 lib 路径添加到
/etc/ld.so.conf
并运行ldconfig 来解决您的问题
作为根用户。not really an answer to your question, but an alternate solution:
you should be able to fix up your issues by adding your new lib path to
/etc/ld.so.conf
and runningldconfig
as root.不能只为需要它的应用程序设置 LD_LIBRARY_PATH 吗?
即,不要将其全局设置为导出变量,而是以
LD_LIBRARY_PATH=/path/to/4.1/libs my_executabel
运行程序?
-k
Can't you set LD_LIBRARY_PATH just for the application that needs it?
I.e. instead of setting it globally as an exported variable, run your program as
LD_LIBRARY_PATH=/path/to/4.1/libs my_executabel
?
-k