简体   繁体   中英

Why clangd on windows cannot find standard header files?

I plan to use noevim on windows operation system. I mainly use cpp and i install msys64 to get gcc/g++ compiler, and gcc toolchain is laid on C:\msys64\mingw64\bin directory. I add revelent path to PATH variable. And I wrote a simple hello world:

```
#include <iostream>
int main (int argc, char *argv[])
{
  std::cout << "hello cruel world" << std::endl;
  return 0;
}
```

The lsp clangd is successfully attached to the buffer, but issues error that 'cannot find iostream'. The lsp.log is as follows with '-log=verbose' option:

```
[START][2022-05-30 18:40:19] LSP logging initiated
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    "I[18:40:26.219] clangd version 14.0.3 (https://github.com/llvm/llvm-project 1f9140064dfbfb0bbda8e51306ea51080b2f7aac)\r\nI[18:40:26.221] Features: windows+grpc\r\nI[18:40:26.221] PID: 12560\r\nI[18:40:26.221] Working directory: C:\\Users\\Astro\r\nI[18:40:26.221] argv[0]: C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe\r\nI[18:40:26.221] argv[1]: -log=verbose\r\nI[18:40:26.221] argv[2]: --query-driver=C:\\msys64\\mingw64\\bin\\g++.exe\r\nI[18:40:26.221] argv[3]: --background-index\r\nI[18:40:26.221] argv[4]: --header-insertion=never\r\nI[18:40:26.221] argv[5]: --completion-style=detailed\r\nI[18:40:26.221] argv[6]: --header-insertion-decorators=false\r\nV[18:40:26.228] User config file is C:\\Users\\Astro\\AppData\\Local\\clangd\\config.yaml\r\nI[18:40:26.228] Starting LSP over stdin/stdout\r\nV[18:40:26.228] <<< {\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"params\":{\"capabilities\":{\"callHierarchy\":{\"dynamicRegistration\":false},\"offsetEncoding\":[\"utf-8\",\"utf-16\"],\"textDocument\":{\"codeAction\":{\"codeActionLiteralSupport\":{\"codeActionKind\":{\"valueSet\":[\"\",\"Empty\",\"QuickFix\",\"Refactor\",\"RefactorExtract\",\"RefactorInline\",\"RefactorRewrite\",\"Source\",\"SourceOrganizeImports\",\"quickfix\",\"refactor\",\"refactor.extract\",\"refactor.inline\",\"refactor.rewrite\",\"source\",\"source.organizeImports\"]}},\"dataSupport\":true,\"dynamicRegistration\":false,\"resolveSupport\":{\"properties\":[\"edit\"]}},\"completion\":{\"completionItem\":{\"commitCharactersSupport\":true,\"deprecatedSupport\":true,\"documentationFormat\":[\"markdown\",\"plaintext\"],\"insertReplaceSupport\":true,\"labelDetailsSupport\":true,\"preselectSupport\":true,\"resolveSupport\":{\"properties\":[\"documentation\",\"detail\",\"additionalTextEdits\"]},\"snippetSupport\":true,\"tagSupport\":{\"valueSet\":[1]}},\"completionItemKind\":{\"valueSet\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},\"contextSupport\":false,\"dynamicRegistration\":false,\"editsNearCursor\":true},\"declaration\":{\"linkSupport\":true},\"definition\":{\"linkSupport\":true},\"documentHighlight\":{\"dynamicRegistration\":false},\"documentSymbol\":{\"dynamicRegistration\":false,\"hierarchicalDocumentSymbolSupport\":true,\"symbolKind\":{\"valueSet\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},\"hover\":{\"contentFormat\":[\"markdown\",\"plaintext\"],\"dynamicRegistration\":false},\"implementation\":{\"linkSupport\":true},\"publishDiagnostics\":{\"relatedInformation\":true,\"tagSupport\":{\"valueSet\":[1,2]}},\"references\":{\"dynamicRegistration\":false},\"rename\":{\"dynamicRegistration\":false,\"prepareSupport\":true},\"signatureHelp\":{\"dynamicRegistration\":false,\"signatureInformation\":{\"activeParameterSupport\":true,\"documentationFormat\":[\"markdown\",\"plaintext\"],\"parameterInformation\":{\"labelOffsetSupport\":true}}},\"synchronization\":{\"didSave\":true,\"dynamicRegistration\":false,\"willSave\":false,\"willSaveWaitUntil\":false},\"typeDefinition\":{\"linkSupport\":true}},\"window\":{\"showDocument\":{\"support\":false},\"showMessage\":{\"messageActionItem\":{\"additionalPropertiesSupport\":false}},\"workDoneProgress\":true},\"workspace\":{\"applyEdit\":true,\"configuration\":true,\"symbol\":{\"dynamicRegistration\":false,\"hierarchicalWorkspaceSymbolSupport\":true,\"symbolKind\":{\"valueSet\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},\"workspaceEdit\":{\"resourceOperations\":[\"rename\",\"create\",\"delete\"]},\"workspaceFolders\":true}},\"clientInfo\":{\"name\":\"Neovim\",\"version\":\"0.7.0\"},\"initializationOptions\":{},\"processId\":13036,\"rootPath\":\"C:\\\\Users\\\\Astro\",\"rootUri\":\"file:///C:/Users/Astro\",\"trace\":\"off\",\"workspaceFolders\":[{\"name\":\"C:/Users/Astro\",\"uri\":\"file:///C:/Users/Astro\"}]}}\r\n\r\nI[18:40:26.229] <-- initialize(1)\r\nI[18:40:26.256] --> reply:initialize(1) 27 ms\r\nV[18:40:26.256] >>> {\"id\":1,\"jsonrpc\":\"2.0\",\"result\":{\"capabilities\":{\"astProvider\":true,\"callHierarchyProvider\":true,\"clangdInlayHintsProvider\":true,\"codeActionProvider\":{\"codeActionKinds\":[\"quickfix\",\"refactor\",\"info\"]},\"compilationDatabase\":{\"automaticReload\":true},\"completionProvider\":{\"allCommitCharacters\":[\" \",\"\\t\",\"(\",\")\",\"[\",\"]\",\"{\",\"}\",\"<\",\">\",\":\",\";\",\",\",\"+\",\"-\",\"/\",\"*\",\"%\",\"^\",\"&\",\"#\",\"?\",\".\",\"=\",\"\\\"\",\"'\",\"|\"],\"resolveProvider\":false,\"triggerCharacters\":[\".\",\"<\",\">\",\":\",\"\\\"\",\"/\",\"*\"]},\"declarationProvider\":true,\"definitionProvider\":true,\"documentFormattingProvider\":true,\"documentHighlightProvider\":true,\"documentLinkProvider\":{\"resolveProvider\":false},\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"\\n\",\"moreTriggerCharacter\":[]},\"documentRangeFormattingProvider\":true,\"documentSymbolProvider\":true,\"executeCommandProvider\":{\"commands\":[\"clangd.applyFix\",\"clangd.applyTweak\"]},\"hoverProvider\":true,\"implementationProvider\":true,\"memoryUsageProvider\":true,\"referencesProvider\":true,\"renameProvider\":{\"prepareProvider\":true},\"selectionRangeProvider\":true,\"semanticTokensProvider\":{\"full\":{\"delta\":true},\"legend\":{\"tokenModifiers\":[\"declaration\",\"deprecated\",\"deduced\",\"readonly\",\"static\",\"abstract\",\"virtual\",\"dependentName\",\"defaultLibrary\",\"usedAsMutableReference\",\"functionScope\",\"classScope\",\"fileScope\",\"globalScope\"],\"tokenTypes\":[\"variable\",\"variable\",\"parameter\",\"function\",\"method\",\"function\",\"property\",\"variable\",\"class\",\"interface\",\"enum\",\"enumMember\",\"type\",\"type\",\"unknown\",\"namespace\",\"typeParameter\",\"concept\",\"type\",\"macro\",\"comment\"]},\"range\":false},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\")\",\"{\",\"}\",\"<\",\">\",\",\"]},\"textDocumentSync\":{\"change\":2,\"openClose\":true,\"save\":true},\"typeDefinitionProvider\":true,\"typeHierarchyProvider\":true,\"workspaceSymbolProvider\":true},\"offsetEncoding\":\"utf-8\",\"serverInfo\":{\"name\":\"clangd\",\"version\":\"clangd version 14.0.3 (https://github.com/llvm/llvm-project 1f9140064dfbfb0bbda8e51306ea51080b2f7aac) windows+grpc x86_64-pc-windows-msvc\"}}}\r\n\r\n"
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    'V[18:40:26.519] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}\r\n\r\n'
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    'I[18:40:26.519] <-- initialized\r\nV[18:40:26.519] <<< {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"#include <iostream>\\r\\nusing namespace std;\\r\\n\\r\\nint main (int argc, char *argv[])\\r\\n{\\r\\n  std::cout << \\"hello cruel world\\" << std::endl;\\r\\n  return 0;\\r\\n}\\r\\n","uri":"file:///C:/Users/Astro/Desktop/main.cpp","version":0}}}\r\n\r\nI[18:40:26.519] <-- textDocument/didOpen\r\n'
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    'I[18:40:26.523] Failed to find compilation database for C:\\Users\\Astro\\Desktop\\main.cpp\r\nI[18:40:26.523] ASTWorker building file C:\\Users\\Astro\\Desktop\\main.cpp version 0 with command clangd fallback\r\n[C:\\Users\\Astro\\Desktop]\r\n"C:\\\\msys64\\\\mingw64\\\\bin\\\\clang" "-resource-dir=C:\\\\Users\\\\Astro\\\\AppData\\\\Local\\\\nvim\\\\lsp_servers\\\\clangd\\\\clangd\\\\lib\\\\clang\\\\14.0.3" -- "C:\\\\Users\\\\Astro\\\\Desktop\\\\main.cpp"\r\nV[18:40:26.541] Driver produced command: cc1 -cc1 -triple x86_64-pc-windows-msvc19.20.0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning "-fcoverage-compilation-dir=C:\\\\Users\\\\Astro\\\\Desktop" -resource-dir "C:\\\\Users\\\\Astro\\\\AppData\\\\Local\\\\nvim\\\\lsp_servers\\\\clangd\\\\clangd\\\\lib\\\\clang\\\\14.0.3" -c-isystem "C:\\\\mingw64\\\\include" -cxx-isystem "C:\\\\Program Files\\\\Intel\\\\CnC\\\\1.0.100\\\\include" -cxx-isystem "C:\\\\Program Files\\\\Intel\\\\oneapi-tbb-2021.1.1\\\\include" -internal-isystem "C:\\\\Users\\\\Astro\\\\AppData\\\\Local\\\\nvim\\\\lsp_servers\\\\clangd\\\\clangd\\\\lib\\\\clang\\\\14.0.3\\\\include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 10.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" -fdeprecated-macro "-fdebug-compilation-dir=C:\\\\Users\\\\Astro\\\\Desktop" -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.20 -std=c++14 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -faddrsig -x c++ "C:\\\\Users\\\\Astro\\\\Desktop\\\\main.cpp"\r\nV[18:40:26.541] Building first preamble for C:\\Users\\Astro\\Desktop\\main.cpp version 0\r\n'
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    'V[18:40:26.559] <<< {"id":2,"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"position":{"character":2,"line":5},"textDocument":{"uri":"file:///C:/Users/Astro/Desktop/main.cpp"}}}\r\n\r\nI[18:40:26.559] <-- textDocument/documentHighlight(2)\r\nV[18:40:26.559] indexed preamble AST for C:\\Users\\Astro\\Desktop\\main.cpp version 0:\r\n  symbol slab: 0 symbols, 128 bytes\r\n  ref slab: 0 symbols, 0 refs, 136 bytes\r\n  relations slab: 0 relations, 24 bytes\r\nV[18:40:26.561] Built preamble of size 225196 for file C:\\Users\\Astro\\Desktop\\main.cpp version 0\r\n'
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    "V[18:40:26.592] indexed file AST for C:\\Users\\Astro\\Desktop\\main.cpp version 0:\r\n  symbol slab: 1 symbols, 4456 bytes\r\n  ref slab: 1 symbols, 1 refs, 4256 bytes\r\n  relations slab: 0 relations, 24 bytes\r\nV[18:40:26.592] Build dynamic index for main-file symbols with estimated memory usage of 11536 bytes\r\n"
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    "I[18:40:26.592] --> textDocument/publishDiagnostics\r\nV[18:40:26.592] >>> {\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"diagnostics\":[{\"code\":\"pp_file_not_found\",\"message\":\"'iostream' file not found\",\"range\":{\"end\":{\"character\":19,\"line\":0},\"start\":{\"character\":9,\"line\":0}},\"relatedInformation\":[],\"severity\":1,\"source\":\"clang\"},{\"code\":\"ext_using_undefined_std\",\"message\":\"Using directive refers to implicitly-defined namespace 'std'\",\"range\":{\"end\":{\"character\":19,\"line\":1},\"start\":{\"character\":16,\"line\":1}},\"relatedInformation\":[],\"severity\":2,\"source\":\"clang\"},{\"code\":\"undeclared_var_use\",\"message\":\"Use of undeclared identifier 'std'\",\"range\":{\"end\":{\"character\":5,\"line\":5},\"start\":{\"character\":2,\"line\":5}},\"relatedInformation\":[],\"severity\":1,\"source\":\"clang\"},{\"code\":\"undeclared_var_use\",\"message\":\"Use of undeclared identifier 'std'\",\"range\":{\"end\":{\"character\":41,\"line\":5},\"start\":{\"character\":38,\"line\":5}},\"relatedInformation\":[],\"severity\":1,\"source\":\"clang\"}],\"uri\":\"file:///C:/Users/Astro/Desktop/main.cpp\",\"version\":0}}\r\n\r\nV[18:40:26.592] ASTWorker running Highlights on version 0 of C:\\Users\\Astro\\Desktop\\main.cpp\r\nI[18:40:26.592] --> reply:textDocument/documentHighlight(2) 33 ms\r\nV[18:40:26.592] >>> {\"id\":2,\"jsonrpc\":\"2.0\",\"result\":[]}\r\n\r\n"
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    'V[18:40:26.931] <<< {"id":3,"jsonrpc":"2.0","method":"textDocument/signatureHelp","params":{"position":{"character":2,"line":5},"textDocument":{"uri":"file:///C:/Users/Astro/Desktop/main.cpp"}}}\r\n\r\nI[18:40:26.931] <-- textDocument/signatureHelp(3)\r\n'
[ERROR][2022-05-30 18:40:26] .../vim/lsp/rpc.lua:420    "rpc"   "C:\\Users\\Astro\\AppData\\Local\\nvim\\lsp_servers\\clangd\\clangd\\bin\\clangd.exe"  "stderr"    'I[18:40:26.967] --> reply:textDocument/signatureHelp(3) 35 ms\r\nV[18:40:26.967] >>> {"id":3,"jsonrpc":"2.0","result":{"activeParameter":0,"activeSignature":0,"signatures":[]}}\r\n\r\n'
```

What i have tried include:

  1. generating compile_commands.json througn cmake tool, failed
  2. add CPP_INCLUDE_* system variable, failed
  3. i configure project with .clangd file, failed The main issue i guess it that clangd cannot find the include path, but i cannot find the solution. On waiting, Friends, help me out!

On Windows, clangd frequently requires the use of the --query-driver option to work correctly.

See https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc for more details.

Note, --query-driver needs to be used together with compile_commands.json , and the argument to --query-driver should match the full path of the compiler executable that appears at the beginning of the commands in the compile_commands.json .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM