【问题标题】:compile_commands.json cannot be foundcompile_commands.json 找不到
【发布时间】:2018-08-26 21:05:48
【问题描述】:

我已经为此苦苦挣扎了一个小时,希望得到一些帮助。我正在尝试使用带有 vs 代码和 cpp 扩展名的 compile_commands.json 文件。下面是我的c_cpp_properties.json 文件和compile_commands.json 文件。

c_cpp_properties.json

...
{
    "name": "Win32",
    "intelliSenseMode": "clang-x64",
    "includePath": [
        "${workspaceRoot}",
        "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++",
        "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/mingw32",
        "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/backward",
        "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include",
        "C:/MinGW/mingw64/include",
        "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include-fixed"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "__GNUC__=6",
        "__cdecl=__attribute__((__cdecl__))"
    ],
    "compileCommands": "${workspaceFolder}/BlitzEngine/builds/Debug/compile_commands.json",
    "browse": {
        "path": [                    
            "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include",
            "C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include-fixed",
            "C:/MinGW/mingw64/include"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
    }
}
...

compile_commands.json

[
{
  "directory": "C:/Users/Emburn/Documents/Projects/BlitzEngine/builds/Debug",
  "command": "C:\\MinGW\\mingw64\\bin\\g++.exe   @CMakeFiles/BlitzEngine.dir/includes_CXX.rsp -g   -o CMakeFiles\\BlitzEngine.dir\\src\\BlitzEngine.cpp.obj -c C:\\Users\\Emburn\\Documents\\Projects\\BlitzEngine\\src\\BlitzEngine.cpp",
  "file": "C:/Users/Emburn/Documents/Projects/BlitzEngine/src/BlitzEngine.cpp"
},
{
  "directory": "C:/Users/Emburn/Documents/Projects/BlitzEngine/builds/Debug",
  "command": "C:\\MinGW\\mingw64\\bin\\g++.exe   @CMakeFiles/BlitzEngine.dir/includes_CXX.rsp -g   -o CMakeFiles\\BlitzEngine.dir\\src\\main.cpp.obj -c C:\\Users\\Emburn\\Documents\\Projects\\BlitzEngine\\src\\main.cpp",
  "file": "C:/Users/Emburn/Documents/Projects/BlitzEngine/src/main.cpp"
},
{
  "directory": "C:/Users/Emburn/Documents/Projects/BlitzEngine/builds/Debug",
  "command": "C:\\MinGW\\mingw64\\bin\\g++.exe   @CMakeFiles/BlitzEngine.dir/includes_CXX.rsp -g   -o CMakeFiles\\BlitzEngine.dir\\src\\RenderWindow.cpp.obj -c C:\\Users\\Emburn\\Documents\\Projects\\BlitzEngine\\src\\RenderWindow.cpp",
  "file": "C:/Users/Emburn/Documents/Projects/BlitzEngine/src/RenderWindow.cpp"
}
]

我尝试过使用不带${workspaceFolder} 的绝对路径,但这也不起作用,每次我保存文件时都会显示它

"${workspaceFolder}/BlitzEngine/builds/Debug/compile_commands.json"
could not be found. Using 'includePath'
setting in c_cpp_properties.json

我的目录树是这样的:

Projects
+-- .vscode
|   +-- c_cpp_properties.json
+-- BlitzEngine
|   +-- Debug
|   |   +-- compile_commands.json
+-- include
|   +-- <header_files>
+-- src
|   +-- <source_files>

提前感谢您的帮助!

【问题讨论】:

  • 这些是你手写的吗?我认为compile_commands.json 的标准做法是让一个工具(如cmake)为你生成它。
  • @StephenNewell 由cmake生成。我只是想让vscode找到文件
  • 您的c_cpp_properties.json 文件中有“compileCommands.json”,但实际文件是蛇形的(即compile_commands.json)。
  • @StephenNewell 哦,哎呀。我只是把它恢复正常。我在解决问题时这样做了。不过还是不行
  • 您的错误消息仍然显示旧路径。此外,您似乎使用的是workspaceFolder 而不是workspaceRoot(根据您的目录布局猜测)。

标签: c++ json cmake visual-studio-code


【解决方案1】:

我没有看到 workspaceFolderc_cpp_properties.json documentation 中列出。那里的示例使用 workspaceRoot,您在之前的配置中就有。

【讨论】:

  • @Julia - 这就是我在曲棍球比赛时回答问题所得到的:)
猜你喜欢
  • 2014-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多