clangd找不到ue5头文件

问题描述 投票:0回答:1

我使用UE5生成了一个C++类,并用VSC打开了它。 Clangd提示找不到“coreminimal.h”,但项目可以正常生成。

ue似乎自动生成了一个c_cpp_properties.json文件和两个compile_commands文件,如下: c_cpp_properties.json

{
"configurations": [
    {
        "name": "obstacleassaultEditor Editor Win64 Development (obstacleassault)",
        "compilerPath": "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "cStandard": "c17",
        "cppStandard": "c++20",
        "intelliSenseMode": "msvc-x64",
        "compileCommands": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_obstacleassault.json"
    },
    {
        "name": "Win32",
        "compilerPath": "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "cStandard": "c17",
        "cppStandard": "c++20",
        "intelliSenseMode": "msvc-x64",
        "compileCommands": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_Default.json"
    }
],
"version": 4

}

compileCommands_Default.json

[
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\MovingPlatform.cpp",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_Default\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\MovingPlatform.h",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_Default\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\obstacleassault.Build.cs",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_Default\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\obstacleassault.cpp",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_Default\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\obstacleassault.h",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_Default\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
}

]

compileCommands_obstacleassault.json

[
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\MovingPlatform.cpp",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_obstacleassault\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\MovingPlatform.h",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_obstacleassault\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\obstacleassault.Build.cs",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_obstacleassault\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\obstacleassault.cpp",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_obstacleassault\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
},
{
    "file": "E:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\obstacleassault.h",
    "arguments": [
        "D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
        "@E:\\unreal\\project\\obstacleassault\\obstacleaasault\\.vscode\\compileCommands_obstacleassault\\obstacleassault.1.rsp"
    ],
    "directory": "E:\\epic\\UE_5.4\\Engine\\Source"
}

]

json文件中指定的rsp文件包含该头文件的父文件夹路径

clangd 的输出是:

I[17:08:47.937] clangd version 18.1.3 (https://github.com/llvm/llvm-project c13b7485b87909fcf739f62cfa382b55407433c0)
I[17:08:47.938] Features: windows+grpc
I[17:08:47.938] PID: 43328
I[17:08:47.938] Working directory: e:\unreal\project\obstacleassault\obstacleaasault
I[17:08:47.938] argv[0]: D:\program\clangd-windows-18.1.3_7\clangd_18.1.3\bin\clangd.exe
I[17:08:47.942] Starting LSP over stdin/stdout
I[17:08:47.942] <-- initialize(0)
I[17:08:47.952] --> reply:initialize(0) 9 ms
I[17:08:47.999] <-- initialized
I[17:08:48.001] <-- textDocument/didOpen
I[17:08:48.003] Failed to find compilation database for e:\unreal\project\obstacleassault\obstacleaasault\Source\obstacleassault\MovingPlatform.h
I[17:08:48.003] ASTWorker building file e:\unreal\project\obstacleassault\obstacleaasault\Source\obstacleassault\MovingPlatform.h version 1 with command clangd fallback
[e:\unreal\project\obstacleassault\obstacleaasault\Source\obstacleassault]
"D:\\program\\mingw64\\bin\\clang" -xobjective-c++-header "-resource-dir=D:\\program\\clangd-windows-18.1.3_7\\clangd_18.1.3\\lib\\clang\\18" -- "e:\\unreal\\project\\obstacleassault\\obstacleaasault\\Source\\obstacleassault\\MovingPlatform.h"
I[17:08:48.012] --> textDocument/clangd.fileStatus
I[17:08:48.024] Built preamble of size 239300 for file e:\unreal\project\obstacleassault\obstacleaasault\Source\obstacleassault\MovingPlatform.h version 1 in 0.01 seconds
I[17:08:48.025] --> workspace/semanticTokens/refresh(0)
I[17:08:48.025] --> textDocument/clangd.fileStatus
I[17:08:48.026] <-- reply(0)
I[17:08:48.027] Indexing c++14 standard library in the context of e:\unreal\project\obstacleassault\obstacleaasault\Source\obstacleassault\MovingPlatform.h
I[17:08:48.043] --> textDocument/publishDiagnostics
I[17:08:48.043] --> textDocument/inactiveRegions
I[17:08:48.043] --> textDocument/clangd.fileStatus
I[17:08:48.078] <-- textDocument/documentLink(1)
I[17:08:48.079] --> reply:textDocument/documentLink(1) 0 ms
I[17:08:48.079] --> textDocument/clangd.fileStatus
I[17:08:48.088] <-- textDocument/inlayHint(2)
I[17:08:48.088] --> reply:textDocument/inlayHint(2) 0 ms
I[17:08:48.088] --> textDocument/clangd.fileStatus
I[17:08:48.089] <-- textDocument/semanticTokens/full(3)
I[17:08:48.090] --> reply:textDocument/semanticTokens/full(3) 0 ms
I[17:08:48.090] --> textDocument/clangd.fileStatus
I[17:08:48.453] <-- $/setTrace
I[17:08:48.453] unhandled notification $/setTrace
I[17:08:48.579] <-- $/setTrace
I[17:08:48.579] unhandled notification $/setTrace
I[17:08:48.684] <-- $/setTrace
I[17:08:48.684] unhandled notification $/setTrace
I[17:08:48.688] <-- textDocument/documentLink(4)
I[17:08:48.688] --> reply:textDocument/documentLink(4) 0 ms
I[17:08:48.688] --> textDocument/clangd.fileStatus
I[17:08:48.694] <-- $/setTrace
I[17:08:48.694] unhandled notification $/setTrace
I[17:08:49.056] <-- $/setTrace
I[17:08:49.056] unhandled notification $/setTrace
I[17:08:49.064] <-- textDocument/foldingRange(5)
I[17:08:49.065] --> reply:textDocument/foldingRange(5) 0 ms
I[17:08:49.065] <-- textDocument/documentSymbol(6)
I[17:08:49.066] --> reply:textDocument/documentSymbol(6) 0 ms
I[17:08:49.066] --> textDocument/clangd.fileStatus
I[17:08:49.094] <-- textDocument/inlayHint(7)
I[17:08:49.094] --> reply:textDocument/inlayHint(7) 0 ms
I[17:08:49.094] --> textDocument/clangd.fileStatus
I[17:08:49.107] <-- $/cancelRequest
I[17:08:49.196] <-- $/cancelRequest
I[17:08:49.223] <-- textDocument/foldingRange(8)
I[17:08:49.223] --> reply:textDocument/foldingRange(8) 0 ms
I[17:08:49.230] <-- textDocument/documentSymbol(9)
I[17:08:49.230] --> reply:textDocument/documentSymbol(9) 0 ms
I[17:08:49.230] --> textDocument/clangd.fileStatus
I[17:08:49.233] <-- textDocument/semanticTokens/full/delta(10)
I[17:08:49.233] --> reply:textDocument/semanticTokens/full/delta(10) 0 ms
I[17:08:49.233] --> textDocument/clangd.fileStatus
I[17:08:49.233] <-- $/cancelRequest
I[17:08:49.234] <-- textDocument/documentLink(11)
I[17:08:49.234] --> reply:textDocument/documentLink(11) 0 ms
I[17:08:49.234] --> textDocument/clangd.fileStatus
I[17:08:49.235] <-- $/cancelRequest
I[17:08:49.256] Indexed c++14 standard library (incomplete due to errors): 12180 symbols, 1150 filtered
I[17:08:49.272] <-- textDocument/foldingRange(12)
I[17:08:49.273] --> reply:textDocument/foldingRange(12) 0 ms
I[17:08:49.557] <-- textDocument/documentSymbol(13)
I[17:08:49.557] --> reply:textDocument/documentSymbol(13) 0 ms
I[17:08:49.557] --> textDocument/clangd.fileStatus
I[17:08:50.107] <-- textDocument/documentSymbol(14)
I[17:08:50.107] --> reply:textDocument/documentSymbol(14) 0 ms
I[17:08:50.107] --> textDocument/clangd.fileStatus
I[17:08:50.254] <-- $/setTrace
I[17:08:50.254] unhandled notification $/setTrace
I[17:08:51.100] <-- textDocument/inlayHint(15)
I[17:08:51.100] --> reply:textDocument/inlayHint(15) 0 ms
I[17:08:51.100] --> textDocument/clangd.fileStatus
I[17:08:51.318] <-- textDocument/foldingRange(16)
I[17:08:51.318] --> reply:textDocument/foldingRange(16) 0 ms
I[17:08:51.393] <-- textDocument/documentSymbol(17)
I[17:08:51.393] --> reply:textDocument/documentSymbol(17) 0 ms
I[17:08:51.393] --> textDocument/clangd.fileStatus
I[17:08:52.102] <-- textDocument/definition(18)
I[17:08:52.102] --> reply:textDocument/definition(18) 0 ms
I[17:08:52.102] --> textDocument/clangd.fileStatus
I[17:08:52.127] <-- textDocument/definition(19)
I[17:08:52.127] --> reply:textDocument/definition(19) 0 ms
I[17:08:52.127] --> textDocument/clangd.fileStatus

我在 Source 文件夹中创建了 compile_commands.json 并将 compileCommands_obstacle.json 的内容复制到其中: enter image description here

这样解决了找不到头文件的问题,但引发了其他问题: enter image description here

clangd 的输出:

I[20:00:22.539] clangd version 18.1.3 (https://github.com/llvm/llvm-project c13b7485b87909fcf739f62cfa382b55407433c0)
I[20:00:22.540] Features: windows+grpc
I[20:00:22.540] PID: 29612
I[20:00:22.540] Working directory: e:\unreal\project\obstacle
I[20:00:22.540] argv[0]: D:\program\clangd-windows-18.1.3_7\clangd_18.1.3\bin\clangd.exe
I[20:00:22.546] Starting LSP over stdin/stdout
I[20:00:22.546] <-- initialize(0)
I[20:00:22.556] --> reply:initialize(0) 9 ms
I[20:00:22.557] <-- initialized
I[20:00:22.559] <-- textDocument/didOpen
I[20:00:22.561] Loaded compilation database from e:\unreal\project\obstacle\Source\compile_commands.json
I[20:00:22.561] --> window/workDoneProgress/create(0)
I[20:00:22.561] Enqueueing 5 commands for indexing
I[20:00:22.562] <-- reply(0)
I[20:00:22.562] --> $/progress
I[20:00:22.562] --> $/progress
I[20:00:22.562] ASTWorker building file e:\unreal\project\obstacle\Source\obstacle\MovingPlatform.h version 1 with command 
[E:\epic\UE_5.4\Engine\Source]
"D:\\program\\vs\\2022community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe" --driver-mode=cl 
/FI "E:\\unreal\\project\\obstacle\\Intermediate\\Build\\Win64\\x64\\UnrealEditor\\Development\\obstacle\\Definitions.obstacle.h" 
/FI "E:\\unreal\\project\\obstacle\\Intermediate\\Build\\Win64\\x64\\obstacleEditor\\Development\\UnrealEd\\SharedPCH.UnrealEd.Project.ValApi.Cpp20.InclOrderOldest.h" 
/I "E:\\epic\\UE_5.4\\Engine\\Source" 
/I "E:\\epic\\UE_5.4\\Engine\\Intermediate\\Build\\Win64\\UnrealEditor\\Inc\\Engine\\UHT"
...........
/I "E:\\epic\\UE_5.4\\Engine\\Source\\ThirdParty\\LibTiff\\Source\\Win64" 
/I "E:\\epic\\UE_5.4\\Engine\\Source\\ThirdParty\\LibTiff\\Source" "-resource-dir=D:\\program\\clangd-windows-18.1.3_7\\clangd_18.1.3\\lib\\clang\\18" -- "e:\\unreal\\project\\obstacle\\Source\\obstacle\\MovingPlatform.h"
I[20:00:22.571] --> textDocument/clangd.fileStatus
I[20:00:22.666] <-- textDocument/documentLink(1)
I[20:00:22.667] <-- textDocument/inlayHint(2)
I[20:00:22.692] <-- $/setTrace
I[20:00:22.692] unhandled notification $/setTrace
I[20:00:22.695] <-- $/setTrace
I[20:00:22.695] unhandled notification $/setTrace
I[20:00:23.087] <-- textDocument/foldingRange(3)
I[20:00:23.128] --> reply:textDocument/foldingRange(3) 41 ms
I[20:00:23.157] <-- textDocument/codeAction(4)
I[20:00:23.158] --> $/progress
I[20:00:23.158] --> $/progress
I[20:00:23.158] --> $/progress
E[20:00:23.182] Indexing E:\unreal\project\obstacle\Source\obstacle\obstacle.Build.cs failed: Couldn't build compiler invocation
I[20:00:23.182] --> $/progress
I[20:00:23.184] <-- $/setTrace
I[20:00:23.184] unhandled notification $/setTrace
I[20:00:23.236] <-- $/setTrace
I[20:00:23.236] unhandled notification $/setTrace
I[20:00:23.277] <-- $/cancelRequest
I[20:00:23.281] <-- textDocument/codeAction(5)
I[20:00:23.368] <-- $/cancelRequest
I[20:00:23.428] <-- textDocument/codeAction(6)
I[20:00:23.457] <-- $/setTrace
I[20:00:23.457] unhandled notification $/setTrace
I[20:00:23.460] <-- $/setTrace
I[20:00:23.460] unhandled notification $/setTrace
I[20:00:23.461] <-- $/cancelRequest
I[20:00:23.461] <-- textDocument/documentLink(7)
I[20:00:23.462] <-- $/cancelRequest
I[20:00:23.462] <-- textDocument/codeAction(8)
I[20:00:23.463] <-- $/cancelRequest
I[20:00:23.464] <-- $/cancelRequest
I[20:00:23.464] <-- textDocument/documentLink(9)
I[20:00:23.464] <-- $/setTrace
I[20:00:23.464] unhandled notification $/setTrace
I[20:00:23.465] <-- textDocument/semanticTokens/full(10)
I[20:00:23.465] <-- textDocument/foldingRange(11)
I[20:00:23.465] --> reply:textDocument/foldingRange(11) 0 ms
I[20:00:23.466] <-- textDocument/documentSymbol(12)
I[20:00:24.749] <-- $/cancelRequest
I[20:00:24.786] <-- textDocument/codeAction(13)
I[20:00:24.786] <-- textDocument/documentSymbol(14)
I[20:00:24.840] <-- $/cancelRequest
I[20:00:24.841] <-- textDocument/codeAction(15)
I[20:00:24.841] <-- $/setTrace
I[20:00:24.841] unhandled notification $/setTrace
I[20:00:24.880] Built preamble of size 16125004 for file e:\unreal\project\obstacle\Source\obstacle\MovingPlatform.h version 1 in 2.31 seconds
I[20:00:24.883] Indexing c17 standard library in the context of e:\unreal\project\obstacle\Source\obstacle\MovingPlatform.h
I[20:00:24.884] --> workspace/semanticTokens/refresh(1)
I[20:00:24.885] <-- reply(1)
I[20:00:24.944] --> textDocument/publishDiagnostics
I[20:00:24.944] --> textDocument/inactiveRegions
I[20:00:24.944] --> reply:textDocument/documentLink(1) 2277 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/inlayHint(2) 2277 ms
I[20:00:24.944] --> reply:textDocument/codeAction(4) 1786 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/codeAction(5) 1662 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/codeAction(6) 1516 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/documentLink(7) 1482 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/codeAction(8) 1481 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/documentLink(9) 1480 ms
I[20:00:24.944] --> reply:textDocument/semanticTokens/full(10) 1479 ms
I[20:00:24.944] --> reply:textDocument/documentSymbol(12) 1478 ms
I[20:00:24.944] --> reply:textDocument/codeAction(13) 158 ms, error: Task was cancelled.
I[20:00:24.944] --> reply:textDocument/documentSymbol(14) 157 ms
I[20:00:24.944] --> reply:textDocument/codeAction(15) 103 ms
I[20:00:24.945] --> textDocument/clangd.fileStatus
[Error - 8:00:24 PM] Request textDocument/documentLink failed.
[object Object]
[Error - 8:00:24 PM] Request textDocument/codeAction failed.
[object Object]
[Error - 8:00:24 PM] Request textDocument/codeAction failed.
[object Object]
[Error - 8:00:24 PM] Request textDocument/codeAction failed.
[object Object]
[Error - 8:00:24 PM] Request textDocument/documentLink failed.
[object Object]
[Error - 8:00:24 PM] Request textDocument/codeAction failed.
[object Object]
[Error - 8:00:24 PM] Request textDocument/codeAction failed.
[object Object]
I[20:00:25.013] <-- textDocument/codeAction(16)
I[20:00:25.013] --> reply:textDocument/codeAction(16) 0 ms
I[20:00:25.013] --> textDocument/clangd.fileStatus
c++ unreal-engine5 clangd
1个回答
0
投票

github上的vsc扩展可以解决这个问题: https://github.com/boocs/unreal-clangd

© www.soinside.com 2019 - 2024. All rights reserved.