Closed ChihHao-Su closed 2 years ago
Do you have any issue / error with the compdb
output?
We do not try to preserve the command line specific formatting, just the semantics.
command
field is a command line, and we need to shell-escape \
-> \\
it, then json-escape it \\
-> \\\\
.The real problem is, compdb will eat up some \. This often happens in path in options and path of source file (and maybe somewhere other). e.g.: /FoCMakeFiles\main.dir\main.cxx.obj will become /FoCMakeFilesmain.dirmain.cxx.obj , D:\PROJ\CPP\HelloWorld\main.cxx will become D:PROJCPPHelloWorldmain.cxx . Therefore clangd cannot parse my c++ code with the compile_commands.json compdb generated.
On 2022/1/18 20:18, Guillaume Papin wrote:
Do you have any issue / error with the |compdb| output? We do not try to preserve the command line specific formatting, just the semantics.
Although ugly, the quadruple backslashes are more correct than the double ones, at least on Linux. This is because the |command| field is a command line, and we need to shell-escape || -> |\| it, then json-escape it |\| -> |\\|.
— Reply to this email directly, view it on GitHub https://github.com/Sarcasm/compdb/issues/24#issuecomment-1015356602, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKCVUXSGX6JCNZAWFGDMVLUWVLCDANCNFSM5MGRZDEA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
There should be another issue that processing compile_commands.json while using MSVC compiler.
After I repair that problem manually (adding missing \\
) :
[
{
"directory": "D:/PROJ/CPP/HelloWorld/BUILD",
"command": "\"C:\\\\DEV_TOOL\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.28.29333\\\\bin\\\\Hostx64\\\\x64\\\\cl.exe\" /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -MDd /FoCMakeFiles\\main.dir\\core.cxx.obj /FdTARGET_COMPILE_PDB /FS -c D:\\PROJ\\CPP\\HelloWorld\\core.cxx",
"file": "D:/PROJ/CPP/HelloWorld/core.cxx"
},
{
"directory": "D:/PROJ/CPP/HelloWorld/BUILD",
"command": "\"C:\\\\DEV_TOOL\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.28.29333\\\\bin\\\\Hostx64\\\\x64\\\\cl.exe\" /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -MDd /FoCMakeFiles\\main.dir\\main.cxx.obj /FdTARGET_COMPILE_PDB /FS -c D:\\PROJ\\CPP\\HelloWorld\\main.cxx",
"file": "D:/PROJ/CPP/HelloWorld/main.cxx"
},
{
"directory": "D:/PROJ/CPP/HelloWorld/BUILD",
"command": "\"C:\\\\DEV_TOOL\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.28.29333\\\\bin\\\\Hostx64\\\\x64\\\\cl.exe\" /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -MDd /FoCMakeFiles\\main.dir\\core.cxx.obj /FdTARGET_COMPILE_PDB /FS D:\\PROJ\\CPP\\HelloWorld\\core.cxx -c D:\\\\PROJ\\\\CPP\\\\HelloWorld\\\\core.hpp",
"file": "D:\\PROJ\\CPP\\HelloWorld\\core.hpp"
}
]
(This is the origin output of compdb: )
[
{
"directory": "D:/PROJ/CPP/HelloWorld/BUILD",
"command": "\"C:\\\\DEV_TOOL\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.28.29333\\\\bin\\\\Hostx64\\\\x64\\\\cl.exe\" /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -MDd /FoCMakeFilesmain.dircore.cxx.obj /FdTARGET_COMPILE_PDB /FS -c D:PROJCPPHelloWorldcore.cxx",
"file": "D:/PROJ/CPP/HelloWorld/core.cxx"
},
{
"directory": "D:/PROJ/CPP/HelloWorld/BUILD",
"command": "\"C:\\\\DEV_TOOL\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.28.29333\\\\bin\\\\Hostx64\\\\x64\\\\cl.exe\" /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -MDd /FoCMakeFilesmain.dirmain.cxx.obj /FdTARGET_COMPILE_PDB /FS -c D:PROJCPPHelloWorldmain.cxx",
"file": "D:/PROJ/CPP/HelloWorld/main.cxx"
},
{
"directory": "D:/PROJ/CPP/HelloWorld/BUILD",
"command": "\"C:\\\\DEV_TOOL\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.28.29333\\\\bin\\\\Hostx64\\\\x64\\\\cl.exe\" /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -MDd /FoCMakeFilesmain.dircore.cxx.obj /FdTARGET_COMPILE_PDB /FS D:PROJCPPHelloWorldcore.cxx -c D:\\\\PROJ\\\\CPP\\\\HelloWorld\\\\core.hpp",
"file": "D:\\PROJ\\CPP\\HelloWorld\\core.hpp"
}
]
clangd shows me Cannot specify 'FoCMakeFiles\main.dir\core.cxx.obj' when compiling multiple source files
in core.hpp.
I think the issue comes from the original command, where you do not have the proper json + shell escapes, i.e. \\\\
instead of \\
.
The original compile_command.json is generated by cmake with Ninja generator.
Preprocessing the input compile_command.json should be a workaround.
Ok, so maybe it's Windows shell parsing rules that differs significantly from POSIX. I would be willing to accept PR that fixes this but don't personally plan to work on it.
Thank you for reporting the issue.
The origin compile_commands.json:
Run with
compdb -p ./ list
:\\
become\\\\
, some disappeared.\"
moved before the option. (e.g.:-I\"D:\\DEV_TOOL\\PCL 1.12.1\\3rdParty\\VTK\\include\\vtk-9.1\"
become\"-ID:\\\\DEV_TOOL\\\\PCL 1.12.1\\\\3rdParty\\\\VTK\\\\include\\\\vtk-9.1\"
)