1

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

screenshot

-D CMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/12.2.0/bin/g++-12 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

Detail Logs

https://pastebin.com/nqCsVAuQ

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"
    ],

screenshot

And I searched for similar problems on google, and I didn't find.

rioV8
  • 24,506
  • 3
  • 32
  • 49
Season0518
  • 11
  • 1
  • Don't use `-I` for system header directories. Perhaps `--sysroot=/usr/local/Cellar/gcc/12.2.0` instead of `-isysroot ...`. (Or `-isysroot` with that path?) – HolyBlackCat Dec 26 '22 at 14:40
  • @HolyBlackCat First of all thank you for your reply Sincerely. First, I tried replacing -isysroot with /usr/local/Cellar/gcc/12.2.0 inside complie_commands, but nothing seems to happen. Then I tried adding "--sysroot=/usr/local/Cellar/gcc/12.2.0" in fallbackFlags, but he still didn't point the header file to the gcc directory, and popped up In included file: 'wchar .h' file not found error – Season0518 Dec 26 '22 at 15:21
  • In case anyone else is curious, the question was also asked at https://github.com/clangd/vscode-clangd/issues/426 and answered there – HighCommander4 Dec 30 '22 at 20:16

0 Answers0