gpt4 book ai didi

c++ - 编译库以便 GDB 自动查找源代码

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:37 24 4
gpt4 key购买 nike

我们正在 Linux 下使用 CMAKE 编译一个库,然后默认安装在 /opt/mylib 下,它的源代码也放在这个文件夹中。

当用户尝试使用 GDB 进行调试时,GDB 不会自动找到库源。

我们如何在不指定任何内容的情况下编译GDB找到源的库?

例如,C++ 标准库就是这样工作的。我可以调试应用程序,而不必告诉 GDB 在哪里可以找到源代码。

注意:这个问题不是关于如何让 GDB 找到源代码(我知道该怎么做),而是关于如何调整 CMakeLists.txt 和不需要的编译过程在 GDB 中手动指定源目录。

最佳答案

您可能正在寻找 -fdebug-prefix-map=old=new GCcflags。

来自manual :

When compiling files residing in directory old, record debugging information describing them as if the files resided in directory new instead. This can be used to replace a build-time path with an install-time path in the debug info. It can also be used to change an absolute path to a relative path by using . for new. This can give more reproducible builds, which are location independent, but may require an extra command to tell GDB where to find the source files. See also -ffile-prefix-map.

如果你想在不安装二进制文件的情况下调试它们,“可能需要一个额外的命令”部分适用。调试已安装的二进制文件就可以了 (TM)。

关于c++ - 编译库以便 GDB 自动查找源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57117562/

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