What value do i have to use for the file - attribute in a compile_commands.json for clang?
Here it says: https://clang.llvm.org/docs/JSONCompilationDatabase.html
file: The main translation unit source processed by this compilation step. This is used by tools as the key into the compilation database. There can be multiple command objects for the same file, for example if the same source file is compiled with different configurations.
[
{ "directory": "/home/user/llvm/build",
"arguments": ["/usr/bin/clang++", "-Irelative", "-DSOMEDEF=With spaces, quotes and \\-es.", "-c", "-o", "file.o", "file.cc"],
"file": "file.cc" },
]
My Files (.c) are in the same Folder as my .compile_commands.json. (Basically everything is just in one folder).
Yet if i do
"file": "myfile.c"
it wont work, and clangd uses the Fallback.
But if i use the absolute path it works for some reason.
So what is the correct non-absoulte path value i need to use please? (i am on windows)
This is documented at https://clang.llvm.org/docs/JSONCompilationDatabase.html#format, specifically this part:
- directory: The working directory of the compilation. All paths specified in the command or file fields must be either absolute or relative to this directory.
So, if the path in the file field is not absolute, it needs to be relative to the directory specified in directory.
As an example, if the source file is located at /home/user/llvm/src/file.cc
, and the value of the directory field is /home/user/llvm/build
, then a correct relative path to put into the file field would be ../src/file.cc
.
EDIT: The documentation page does not say anything about whether the directory field itself must be absolute, or if it's allowed to be relative (and if so, what it's interpreted relative to).
However, looking at the implementation, I can see that there is no handling of directory being a relative path, it's assumed to be absolute.
This could probably be clarified in the documentation.