C++ LSP CCLS 检查出现莫名错误,程序可以编译通过,能够执行

本机clang信息: $ clang -v -fsyntax-only -x c++ /dev/null

clang version 10.0.0

Target: x86_64-apple-darwin19.6.0

Thread model: posix

InstalledDir: /usr/local/opt/llvm/bin

(in-process)

“/usr/local/Cellar/llvm/10.0.0_3/bin/clang-10” -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -fsyntax-only -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-rounding-math -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir /usr/local/Cellar/llvm/10.0.0_3/lib/clang/10.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -stdlib=libc++ -internal-isystem /usr/local/opt/llvm/bin/…/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/local/include -internal-isystem /usr/local/Cellar/llvm/10.0.0_3/lib/clang/10.0.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -fdeprecated-macro -fdebug-compilation-dir /Users/donald/coding/cplus -ferror-limit 19 -fmessage-length 123 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -x c++ /dev/null

clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin19.6.0

ignoring nonexistent directory “/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/v1”

ignoring nonexistent directory “/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/local/include”

ignoring nonexistent directory “/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/Library/Frameworks”

#include “…” search starts here:

#include <…> search starts here:

/usr/local/opt/llvm/bin/…/include/c++/v1

/usr/local/Cellar/llvm/10.0.0_3/lib/clang/10.0.0/include

/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include

/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks (framework directory)

End of search list.

project root下的.ccls文件内容 $ cat .ccls

clang

%c -std=c11

%cpp -std=c++2a

%h %hpp --include=Global.h

-Iinc

-DMACRO

哎呀,终于在外网找到答案了 clang -v -fsyntax-only -x c++ /dev/null will output a list of paths/header folders clang would look for. (I assume that there are so many of them because OSX update also changes the location of many of these header files, thus to keep backward compatibility, Apple Clang would just scan through all possible paths) p.s. without including all of these paths in extraArgs, some macros such as size_t might not be found They are all over the place!! :sweat_smile:

clang -print-resource-dir will give another initialization options (I’m not personally sure this config has any effect, but I followed this faq)

configure my emacs:

(after! ccls
  (setq ccls-initialization-options
        '(:clang (:extraArgs ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1"
                              "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
                              "-isystem/usr/local/include"
                              "-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include"
                              "-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"
                              "-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
                              "-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"]
                  :resourceDir "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0")))
  )