vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

Compile errors when using embedded clangd

Open mmatrosov opened this issue 4 years ago • 0 comments

I've just installed clangd on my VS Code and it suggested I download clangd server. I agreed, but this led to multiple compile errors. For instance, for this code:

class TCPResolver {
 public:
  using ResolverImpl = boost::asio::ip::tcp::resolver;
  using Endpoint = ResolverImpl::endpoint_type;
  using ResolveCallback = Function<void(error_code, Endpoint)>;
  ...

I had the following error: image

Which is clear nonsense - the ResolverImpl is declared one line above. Here are some logs:

I[15:27:42.499] clangd version 12.0.0 (https://github.com/clangd/llvm-project 8a844a3a321ea56da21af4d48433ad493b1bcfae)
I[15:27:42.499] PID: 3708783
I[15:27:42.499] Working directory: /home/mmatrosov/dev/crypto
I[15:27:42.499] argv[0]: /home/mmatrosov/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/bin/clangd
I[15:27:42.499] argv[1]: -compile-commands-dir=/home/mmatrosov/dev/crypto/build_release
I[15:27:42.499] Starting LSP over stdin/stdout
I[15:27:42.527] <-- initialize(0)
I[15:27:42.527] Client supports legacy semanticHighlights notification and standard semanticTokens request, choosing the latter (no notifications).
I[15:27:42.528] --> reply:initialize(0) 1 ms
I[15:27:42.548] <-- initialized
I[15:27:42.548] <-- textDocument/didOpen
I[15:27:42.552] Loaded compilation database from /home/mmatrosov/dev/crypto/build_release/compile_commands.json
I[15:27:42.553] --> window/workDoneProgress/create(0)
I[15:27:42.553] Enqueueing 397 commands for indexing
I[15:27:42.553] ASTWorker building file /home/mmatrosov/dev/crypto/src/network/tcp_resolver.h version 1 with command inferred from /home/mmatrosov/dev/crypto/src/network/tcp_resolver.cpp
[/home/mmatrosov/dev/crypto/build_release]
/usr/bin/clang++-11 --driver-mode=g++ <...>  -c -x c++-header -std=c++20 /home/mmatrosov/dev/crypto/src/network/tcp_resolver.h -fsyntax-only -resource-dir=/home/mmatrosov/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0

I compared this with the actual command line from compile_commads.json, and figured out the extension added these args:

--driver-mode=g++
-resource-dir=/home/mmatrosov/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0

I tried to run this very command in the command line and got the same errors. I then removed the -resource-dir arg and the file compiled just fine.

I then installed clangd-11 in the system and specified the path to it in the settings. The problem went away. The -resource-dir in the logs also changed:

-resource-dir=/usr/lib/llvm-11/lib/clang/11.1.0

So it seems like the incompatible version from clang-12 was used by default, even though I compile my code with clang-11. Also, I was totally not expecting that the extension would add anything to the compile command from the compile_commands.json file, even though it is supposed to be self-contained.

System information Clangd version: 12 (embedded), 11 (system-installed) clangd extension version: 0.1.11 Operating system: Ubuntu 20.04

mmatrosov avatar Jun 17 '21 12:06 mmatrosov