clang错误中的完整代码路径

Full code paths in clang errors

本文关键字:代码 路径 错误 clang      更新时间:2023-10-16

我正在寻找cl命令/FC的clang等效。我需要我的构建工具的完整路径来解析和打开带有错误的代码文件。

https://msdn.microsoft.com/en-us/library/027c4t2s.aspx

CFLAGS+= -fdiagnostics-absolute-paths

您需要在命令行上为文件指定一个完全限定的或相对的路径,而不是只传递文件名。在下面的示例中,调试器将不知道在哪里找到"blah"。因为我编译时只指定了文件名:

~ pwd
/mnt/scratch/myproject/src
~ clang++ blah.cc -c -o /mnt/scratch/myproject/build/blah.o
~ cd ../build
~ clang++ *.o -o myprogram

…但是,如果我这样做:

~ pwd
/mnt/scratch/myproject
~ clang++ /mnt/scratch/myproject/src/blah.cc -c -o /mnt/scratch/myproject/build/blah.o
# or:
~ clang++ src/blah.cc -c -o build/blah.o
# ...

…然后,它将完全限定路径或相对路径嵌入到调试部分中。

如果使用部分限定的路径,则必须告诉GDB在哪里查找代码。您可以在这里查看相关文档,不过两个gdb命令可能会有所帮助:

# This will cause gdb to look in "path2" instead of "path1"
(gdb) set substitute-path path1 path2
# This allows you to give a list of directories to search for your source.
# note that if you give relative paths on the command-line, it'll concatenate
# these paths and the relative path used at compile-time.
(gdb) set directories path [path ...]