I'm trying to use vscode-clangd plugin to complete my code. I've tried to use--query-driver and other parameters. Neither of them can recognize g+++ 12's header file properly, but clions that are also clangd based can recognize gcc's header file properly. Is this a bug? How should I fix it?
I tried to open the same CMake project with two compilers. These are their differences
This is the header directory given by vscode. screenshot
settings.json
{
"C_Cpp.intelliSenseEngine": "Disabled",
"clangd.arguments": [
"-log=verbose",
"--query-driver=/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin22-g++-12,/usr/local/Cellar/gcc/12.2.0/bin/g++-12",
"--compile-commands-dir=/Users/season/Projects/cplusplus/Projects/acm_cmake/cmake-build-debug/compile_commands.json"
],
"cmake.configureOnOpen": true,
"cmake.configureArgs": [
"-D CMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/12.2.0/bin/g++-12",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
]
}
Compile_commands.json
[
{
"directory": "/Users/season/Projects/cplusplus/Projects/acm_cmake/cmake-build-debug",
"command": "/usr/local/Cellar/gcc/12.2.0/bin/g++-12 -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.0.sdk -fdiagnostics-color=always -std=gnu++14 -o CMakeFiles/acm_cmake.dir/main.cpp.o -c /Users/season/Projects/cplusplus/Projects/acm_cmake/main.cpp",
"file": "/Users/season/Projects/cplusplus/Projects/acm_cmake/main.cpp"
}
]
CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(acm_cmake)
set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(acm_cmake main.cpp)
This is the header directory given by Clion. screenshot
Clion's CMake options
-D CMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/12.2.0/bin/g++-12 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
Detail Logs
System information
$ clangd --version
Homebrew clangd version 15.0.6
Features: mac+xpc
Platform: x86_64-apple-darwin22.1.0
clangd extension version:
clangd v0.1.15
Operating system:
macOS Ventura 13.0.1 (22A400)
I tried to use - I fallback arguments to specify the directory of the header file, but clangd will give many error prompts.
"clangd.fallbackFlags": [
"-I/usr/local/Cellar/gcc/12.2.0/include/c++/12",
"-I/usr/local/Cellar/gcc/12.2.0/include/c++/12/x86_64-apple-darwin22"
],
And I searched for similar problems on google, and I didn't find.