-rpath 和 -L 有什么区别? [英] What's the difference between -rpath and -L?

查看:36
本文介绍了-rpath 和 -L 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gccld 提供了多种指定库搜索路径的方法——其中包括 -rpath-L 标志.联机帮助页显示这两个标志之间没有区别,实际上是说每个标志都将一个库添加到库搜索路径中.然而,这两个标志完全做同样的事情似乎很奇怪.这两个选项之间有什么区别(如果有)?

gcc and ld provide many ways to specify a search path for libraries—among them the -rpath and -L flags. The manpages reveal no differences between these two flags, effectively saying each flag adds a library to the library search path. Yet it seems strange that both flags do exactly the same thing. What are the differences, if any, between these two options?

推荐答案

您必须阅读一些过时的联机帮助页副本(已添加重点):

You must be reading some outdated copies of the manpages (emphasis added):

-rpath=dir
     将目录添加到运行时库搜索路径.这是使用
     将 ELF 可执行文件与共享对象链接时.所有 -rpath
     参数被连接起来并传递给运行时链接器,
     使用它们在运行时定位共享对象.

-rpath=dir
      Add a directory to the runtime library search path. This is used
      when linking an ELF executable with shared objects. All -rpath
      arguments are concatenated and passed to the runtime linker, which
      uses them to locate shared objects at runtime.

对比

-L 搜索目录
--library-path=searchdir
     将路径 searchdir 添加到 ld 将搜索的路径列表
     存档库和ld控制脚本.

-L searchdir
--library-path=searchdir
      Add path searchdir to the list of paths that ld will search for
      archive libraries and ld control scripts.

因此,-L 告诉 ld 链接时在哪里查找要链接的库.您在构建树中的库时使用它(例如),它将被 make install 放入正常的系统库路径中.--rpath 另一方面,将该路径存储在可执行文件中,以便运行时动态链接器可以找到库.当您的库位于系统库搜索路径之外时,您可以使用它.

So, -L tells ld where to look for libraries to link against when linking. You use this (for example) when you're building against libraries in your build tree, which will be put in the normal system library paths by make install. --rpath, on the other hand, stores that path inside the executable, so that the runtime dynamic linker can find the libraries. You use this when your libraries are outside the system library search path.

这篇关于-rpath 和 -L 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆