gpt4 book ai didi

gcc - -rpath 和 -L 有什么区别?

转载 作者:行者123 更新时间:2023-12-03 05:15:48 24 4
gpt4 key购买 nike

GNU 编译器集合(又名 gcc)和 ld 提供了多种指定库搜索路径的方法,其中包括 -rpath-L 标志。联机帮助页显示这两个标志之间没有差异,实际上是说每个标志都将一个库添加到库搜索路径中。然而,这两个标志的作用完全相同似乎很奇怪。这两个选项之间有什么区别(如果有)?

最佳答案

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

-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 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 将该路径存储在可执行文件中,以便运行时动态链接器可以找到库。当您的库位于系统库搜索路径之外时,可以使用此选项。

关于gcc - -rpath 和 -L 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8482152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com