如何打印ld(链接器)搜索路径 [英] How to print the ld(linker) search path

查看:551
本文介绍了如何打印ld(链接器)搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打印按照 ld 查找的搜索路径的方法是什么?

What is the way to print the search paths that in looked by ld in the order it searches.

推荐答案

我不确定是否有简单打印完整有效搜索路径的选项。

I'm not sure that there is any option for simply printing the full effective search path.

但是:搜索路径由<在命令行上输入code> -L 选项,然后按 SEARCH_DIR(...)添加到搜索路径中的目录链接器脚本中的指令。所以你可以解决这个问题,如果你能看到这两者,你可以这样做:

But: the search path consists of directories specified by -L options on the command line, followed by directories added to the search path by SEARCH_DIR("...") directives in the linker script(s). So you can work it out if you can see both of those, which you can do as follows:

如果你调用 ld 直接:

If you're invoking ld directly:


  • -L ve说他们是。

  • 要查看链接描述文件,请添加 - verbose 选项。查找 SEARCH_DIR(...)指令,通常位于输出的顶部附近。 (请注意,对于 ld 的每次调用,这些都不一定相同 - 链接器具有许多不同的内置默认链接器脚本,并根据各种内容)

  • The -L options are whatever you've said they are.
  • To see the linker script, add the --verbose option. Look for the SEARCH_DIR("...") directives, usually near the top of the output. (Note that these are not necessarily the same for every invocation of ld -- the linker has a number of different built-in default linker scripts, and chooses between them based on various other linker options.)

如果您通过 gcc 连接:


  • 您可以将 -v 选项传递给 gcc ,以便它显示它如何调用链接器。事实上,它通常不直接调用 ld ,而是间接通过名为 collect2 的工具(它居于它的内部目录),然后调用 ld 。这将告诉你正在使用 -L 选项。

  • 您可以添加 -Wl, - 详细 gcc 选项以使它传递给 - verbose 到链接器,如上所述查看链接描述文件。

  • You can pass the -v option to gcc so that it shows you how it invokes the linker. In fact, it normally does not invoke ld directly, but indirectly via a tool called collect2 (which lives in one of its internal directories), which in turn invokes ld. That will show you what -L options are being used.
  • You can add -Wl,--verbose to the gcc options to make it pass --verbose through to the linker, to see the linker script as described above.

这篇关于如何打印ld(链接器)搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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