Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccls c++ header completion on osx #191

Closed
DL-85 opened this issue Jan 5, 2019 · 38 comments
Closed

ccls c++ header completion on osx #191

DL-85 opened this issue Jan 5, 2019 · 38 comments

Comments

@DL-85
Copy link

DL-85 commented Jan 5, 2019

OS: macOS Mojave 10.14.2
emacs: 26.1
Spacemacs: develop
Problem: header file can't be completed correctly
image

And ccls reported error on string and vector even if the correct header file is included
image

.ccls content:
%clang
-Wall
%c -std=gnu11
%cpp -std=c++11
%cpp -stdlib=libc++

CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(test_ccls)
set(CMAKE_CXX_STANDARD 11)
include_directories(/usr/local/Cellar/llvm/7.0.0_1/include/c++/v1)
add_executable(test_ccls main.cpp)

I have generated and linked the compile_commands.json file.
Solutions mentioned in #125 and #160 seem not work here.
Solutions in wiki https://github.com/MaskRay/ccls/wiki/FAQ#some-cc-headers-are-not-recognized also don't work.

@DL-85
Copy link
Author

DL-85 commented Jan 5, 2019

I try the ccls installed by "brew install --HEAD ccls" and build ccls from source code(master), same problem happened.

@DL-85 DL-85 changed the title ccls c++ header completion in osx ccls c++ header completion on osx Jan 5, 2019
@madscientist
Copy link
Contributor

By "solutions in wiki didn't work" do you mean, you verified that the clang resource directory is available and in the correct place based on the log output?

Also I should point out that your compile_commands.json is not being used here. If the .ccls file exists then it will be used and compile_commands.json will not be used. You can use both, but to do so you need to (a) remove the %clang from your .ccls file and (b) add %compile_commands.json to your .ccls file. Note this likely won't work with the homebrew version (I have no idea how old it is but this feature is just weeks old). More info is available in https://github.com/madscientist/ccls/wiki/Customization#ccls-file and https://github.com/madscientist/ccls/wiki/Project-Setup (I reworked the wiki but @MaskRay is taking a well-earned break: he pulled some but not all of my changes so there are broken links in his version of the wiki--I'm sure he'll resolve this quickly once he's back online).

I don't really understand why you're hardcoding a path to /usr/local in your CMakeLists.txt if you're using clang (the default compiler) on MacOS but I don't know much about either one so maybe it's needed.

@MaskRay
Copy link
Owner

MaskRay commented Jan 6, 2019

Thanks to @madscientist !

#include "header" (Text)
#include

(Text)

When the line is #inc|, this is an expected result (code patterns) when you ask for completion.

https://github.com/maskray/ccls/blob/master/src/messages/textDocument_completion.cc#L476
  CCOpts.IncludeCodePatterns = StringRef(buffer_line).ltrim().startswith("#");

You'll get a list of filenames (what you might expect) if the line is #include " or #include <.

If you use company-lsp, there is an option company-lsp-enable-recompletion (defaults to t). When the line is #inc|, after selecting the #include <header> (Text) completion item, company-complete-selection inserts lucde < and triggers the completion again. #include " may not work due to some company or companylsp issues (related: " is used for string literals).

%c -std=gnu11

  • GCC 5/Clang 3.6 defaults to -std=gnu11
  • GCC 8 defaults to -std=gnu17

%cpp -std=c++11

GCC 6/Clang 6 default to -std=gnu++14

.ccls content:
%clang
-Wall
%c -std=gnu11
%cpp -std=c++11
%cpp -stdlib=libc++
Solutions mentioned in #125 and #160 seem not work here.

#125 is irrelevant to ccls (completion feature missing in the client)

#160 is related. Have you read #160 (comment) ?

I don't have a Mac OS X to verify, but can you set -ccc-install-dir like the following:

%clang
-ccc-install-dir
/usr/local/Cellar/llvm/7.0.0_1/bin
%cpp -stdlib=libc++

@DL-85
Copy link
Author

DL-85 commented Jan 6, 2019

By "solutions in wiki didn't work" do you mean, you verified that the clang resource directory is available and in the correct place based on the log output?

Also I should point out that your compile_commands.json is not being used here. If the .ccls file exists then it will be used and compile_commands.json will not be used. You can use both, but to do so you need to (a) remove the %clang from your .ccls file and (b) add %compile_commands.json to your .ccls file. Note this likely won't work with the homebrew version (I have no idea how old it is but this feature is just weeks old). More info is available in https://github.com/madscientist/ccls/wiki/Customization#ccls-file and https://github.com/madscientist/ccls/wiki/Project-Setup (I reworked the wiki but @MaskRay is taking a well-earned break: he pulled some but not all of my changes so there are broken links in his version of the wiki--I'm sure he'll resolve this quickly once he's back online).

I don't really understand why you're hardcoding a path to /usr/local in your CMakeLists.txt if you're using clang (the default compiler) on MacOS but I don't know much about either one so maybe it's needed.

I now use the ccls build from source using the command "cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DSYSTEM_CLANG=ON -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm"
I remove the compile_commands.json file and just use .ccls file.
The ccls.log output "initialize.cc:327 I use -resource-dir=/usr/local/Cellar/llvm/7.0.0_1/lib/clang/7.0.0", and the command " clang++ -print-resource-dir" output "/usr/local/Cellar/llvm/7.0.0_1/lib/clang/7.0.0"

@DL-85
Copy link
Author

DL-85 commented Jan 6, 2019

@MaskRay I try #include <, but still got nothing.
image
I try modified .ccls to:
%clang
-ccc-install-dir
/usr/local/Cellar/llvm/7.0.0_1/bin
%cpp -stdlib=libc++
but not work.

I notice that the command "clang++ -fsyntax-only -v -xc++ /dev/null -stdlib=libc++" output is
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
"/usr/local/Cellar/llvm/7.0.0_1/bin/clang-7" -cc1 -triple x86_64-apple-macosx10.14.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 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v -resource-dir /usr/local/Cellar/llvm/7.0.0_1/lib/clang/7.0.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/didi -ferror-limit 19 -fmessage-length 88 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -x c++ /dev/null
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target x86_64-apple-darwin18.2.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/Cellar/llvm/7.0.0_1/include/c++/v1
/usr/local/include
/usr/local/Cellar/llvm/7.0.0_1/lib/clang/7.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list

Is it correct?
#include <...> search starts here:
/usr/local/Cellar/llvm/7.0.0_1/include/c++/v1
/usr/local/include
/usr/local/Cellar/llvm/7.0.0_1/lib/clang/7.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
c++ header files are in /usr/local/Cellar/llvm/7.0.0_1/include/c++/v1, but ccls.log output "initialize.cc:327 I use -resource-dir=/usr/local/Cellar/llvm/7.0.0_1/lib/clang/7.0.0", Does this cause the problem?
Now I'm trying rebuild ccls use the cland+llvm download by CMake.

@MaskRay
Copy link
Owner

MaskRay commented Jan 6, 2019

Is it correct?

I don't use Mac OS X so I'm not sure. libc++ search directory looks like somewhere/include/c++/v1.
Clang resource directory is somewhere/lib/clang/7.0.1.

On Linux, clang is typically installed at /usr/bin/clang and the libstdc++ search directory is at /usr/include/c++/8. clangDriver locates the executable path and searches for some relative paths to get the potential libstdc++/libc++ search directory. If you don't install ccls, the ccls executable is likely not in /usr/bin/ccls and you may use -ccc-install-dir.

Can you print some variables related to HeaderOpts.UserEntries around project.cc:190 as #160 suggests?

@DL-85
Copy link
Author

DL-85 commented Jan 7, 2019

Does ccls support clang 10.0.0?
It seems that xcode in osx 10.14.2 use clang 10.0.0 by default, and all the related paths like Clang_LIBRARY Clang_INCLUDE_DIR LLVM_INCLUDE_DIR LLVM_BUILD_INCLUDE_DIR is seted to clang 10.0.0.
The command "clang --version" on mac10.14.2 output:
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

When I build ccls using command "cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DSYSTEM_CLANG=ON" , the cmake report error:
-- Could NOT find Clang (missing: Clang_LIBRARY Clang_INCLUDE_DIR LLVM_INCLUDE_DIR LLVM_BUILD_INCLUDE_DIR) (found suitable version "10.0.0", minimum required is "6.0.0")

I explored the directory of "/Library/Developer/CommandLineTools/usr", the include directory have "FlexLexer.h c++ swift", while in clang+llvm 7.0.0 the include directory contains "c++ clang clang-c lld llvm llvm-c polly". And the lib directory in /Library/Developer/CommandLineTools/usr(maybe the clang 10.0.0 root directory) and the clang+llvm 7.0.0 is very different.
Could the executive file clang(7.0.0) using the right library, or the clang(7.0.0) I used to build ccls may try to use the library in clang(10.0.0), while the library is not backward-compatible?
So the ccls couldn't work well for the wrong clang+llvm library.

@DL-85
Copy link
Author

DL-85 commented Jan 7, 2019

Is it correct?

I don't use Mac OS X so I'm not sure. libc++ search directory looks like somewhere/include/c++/v1.
Clang resource directory is somewhere/lib/clang/7.0.1.

On Linux, clang is typically installed at /usr/bin/clang and the libstdc++ search directory is at /usr/include/c++/8. clangDriver locates the executable path and searches for some relative paths to get the potential libstdc++/libc++ search directory. If you don't install ccls, the ccls executable is likely not in /usr/bin/ccls and you may use -ccc-install-dir.

Can you print some variables related to HeaderOpts.UserEntries around project.cc:190 as #160 suggests?

I modified the source code of ccls as #160 and rebuild ccls. But nothing is output, no file is generated in the path I used to initilized fstream f, why?
The function GetSearchDirs is not called correnctly on osx?

@FirstLoveLife
Copy link
Contributor

FirstLoveLife commented Jan 7, 2019

Does ccls support clang 10.0.0?
It seems that xcode in osx 10.14.2 use clang 10.0.0 by default, and all the related paths like Clang_LIBRARY Clang_INCLUDE_DIR LLVM_INCLUDE_DIR LLVM_BUILD_INCLUDE_DIR is seted to clang 10.0.0.
The command "clang --version" on mac10.14.2 output:
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Take a look at https://en.wikipedia.org/wiki/Xcode#Latest_versions and https://trac.macports.org/wiki/XcodeVersionInfo

Your llvm version is 6.0.1 or 7.0.x

BTW, does c header file work and what's your M-x company-diag output?

@DL-85
Copy link
Author

DL-85 commented Jan 7, 2019

Does ccls support clang 10.0.0?
It seems that xcode in osx 10.14.2 use clang 10.0.0 by default, and all the related paths like Clang_LIBRARY Clang_INCLUDE_DIR LLVM_INCLUDE_DIR LLVM_BUILD_INCLUDE_DIR is seted to clang 10.0.0.
The command "clang --version" on mac10.14.2 output:
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Take a look at https://en.wikipedia.org/wiki/Xcode#Latest_versions and https://trac.macports.org/wiki/XcodeVersionInfo

Your llvm version is 6.0.1.

I have tried use the llvm 7.0.0 downloaded by CMake but problem still happened.

@DL-85
Copy link
Author

DL-85 commented Jan 7, 2019

I use cquery for the lsp-backend and things work well.
Does it provide any clue?

@MaskRay
Copy link
Owner

MaskRay commented Jan 7, 2019

I modified the source code of ccls as #160 and rebuild ccls. But nothing is output, no file is generated in the path I used to initilized fstream f, why?

The next major release of clang+llvm (8.0) will support builtin header file completion. There are two header completion backends in ccls:

  • #if LLVM_VERSION_MAJOR < 8, use ProjectProcessor::GetSearchDirs and include_complete.cc (similar to cquery's approach). compile_commands.json entries are preprocessed and the search directories are stored in ccls::Project::Folder::search_dir2kind.
  • otherwise, use builtin header file completion (clang/lib/Sema)

Can you check the value of the macro LLVM_VERSION_MAJOR? It is probably defined in include/llvm/Config/llvm-config.h

while the library is not backward-compatible?

It is not compatible. I'm very confused as you use both 7.0.0 and 10.0.0 . For CMAKE_CXX_COMPILER, you may use the clang 10.0.0 integrated in xcode, but its library may cause conflicts.

I have tried use the llvm 7.0.0 downloaded by CMake but problem still happened.

Did you mean cmake -GNinja -H. -BRelease? # The default -DSYSTEM_CLANG=OFF downloads prebuilt archives from releases.llvm.org

Can you dump the values of CMAKE_CXX_COMPILER and FIND_PACKAGE_MESSAGE_DETAILS_Clang in Release/CMakeCache.txt? -DDEFAULT_RESOURCE_DIRECTORY= in Release/build.ninja?

@DL-85
Copy link
Author

DL-85 commented Jan 7, 2019

Yes, it will download and extract clang+llvm7.0 to the Release directory.

Config/llvm-config.h
69:#define LLVM_VERSION_MAJOR 7

CMakeCache.txt
37:CMAKE_CXX_COMPILER:FILEPATH=/Library/Developer/CommandLineTools/usr/bin/c++
345://ADVANCED property for variable: CMAKE_CXX_COMPILER
346:CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1

CMakeCache.txt
459:FIND_PACKAGE_MESSAGE_DETAILS_Clang:INTERNAL=[/Users/dl-85/workspace/ccls/Release/clang+llvm-7.0.0-x86_64-apple-darwin/lib/libclangIndex.a][/Users/dl-85/workspace/ccls/Release/clang+llvm-7.0.0-x86_64-apple-darwin/include][/Users/dl-85/workspace/ccls/Release/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang][/Users/dl-85/workspace/ccls/Release/clang+llvm-7.0.0-x86_64-apple-darwin/lib/clang/7.0.0][7.0.0][/Users/dl-85/workspace/ccls/Release/clang+llvm-7.0.0-x86_64-apple-darwin/include][/Users/dl-85/workspace/ccls/Release/clang+llvm-7.0.0-x86_64-apple-darwin/include][v7.0.0(6.0.0)]

@DL-85
Copy link
Author

DL-85 commented Jan 7, 2019

@FirstLoveLife
c header file also doesn't work.
M-x company-diag output
Emacs 26.1 (x86_64-apple-darwin14.5.0) of 2018-05-31 on builder10-10.porkrind.org
Company 0.9.9
company-backends: (company-lsp)
Used backend: company-lsp
Major mode: c++-mode
Prefix: ""
Completions: none

@LeadroyaL
Copy link

@DL-85 Hi, I have the same problem with you. Finally I found a solution which cost me almost one day.

Environment :

  • I use Atom editor and latest MacOS.
  • Compile llvm+clang by myself, install at $LLVM_HOME
  • Compile ccls by myself. with -DSYSTEM_CLANG=ON -DCMAKE_PREFIX_PATH=$LLVM_HOME

Final solution:

  • use -isystem /Library/Developer/CommandLineTools/usr/include/c++/v1 in .ccls

The position could be near the CommandLineTools, maybe it is in Xcode.app (/Application/Xcode.app/xxxxxxxxx). You can find it by this command

➜  babycase gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

some tips here:

  • remember to clean the cache by delete files.
  • remember to restart the Atom.app.
  • Make sure the project.cc:190 contains value.
for (auto &E : HeaderOpts.UserEntries) {

In my case, the root cause is HeaderOpts.UserEntries is empty.

My debug steps:

I add insert some code in project.cc.

HeaderOpts.AddPath("/Users/leadroyal/pllvm/r/include/c++/v1/", clang::frontend::IncludeDirGroup::System, false, false);

or

HeaderOpts.AddPath("/Library/Developer/CommandLineTools/usr/include/c++/v1", clang::frontend::IncludeDirGroup::System, false, false);

Then compile ccls, clean cache, restart software. Both of the modifications is effective.

image

@leetking
Copy link

I use ArchLinux and it cant complete header file too but when I switch to cquery completion works well.

OS: test in docker container, using base/archlinux:lastest
neovim: install from pacman, the version is v0.3.3
vim-plug: the lastest
coc.nvim: installed through vim-plug
ccls: installed through the AUR package ccls-git

My coc.nvim config showen as below:

    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "cuda", "objc", "objcpp"],
      "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
      "trace.server": "verbose",
      "initializationOptions": {
         "cacheDirectory": "/tmp/ccls"
       }
    },

are there any possible to recur this problem or need any more details?

@MaskRay
Copy link
Owner

MaskRay commented Jan 13, 2019

This was always an issue with clang < 8 on Mac OS X. The work around is to pass -isystem /Library/Developer/CommandLineTools/usr/include/c++/v1, either through clang.extraArgs or .ccls.

It was actually a clangDriver issue (fixed in clang 8), but the ccls 0.20181225.* release was also at fault (the "Extend .ccls ..." commit (project.cc:GetSearchDirs broke the clang.extraArgs workaround; -isystem ... in .ccls still works) I've fixed clang.extraArgs and pushed a new release https://github.com/MaskRay/ccls/releases/tag/0.20181225.6

To make header completion work with clang < 8 on Mac OS X, use a shell script wrapper:

#!/bin/sh
exec /path/to/ccls/Release/ccls -init='{"clang":{"extraArgs":["-isystem", "/Library/Developer/CommandLineTools/usr/include/c++/v1"]}}' "$@"

When clang < 8 (I use clang trunk personally so this configuration gets less testing), the header completion backends is project.cc:GetSearchDirs+include_complete.cc. GetSearchDirs leverages clangDriver to get system and user search directories.
On Mac OS X 10.9+, libc++ is the default C++ stdlib implementation. The system libc++ search directory, however, was weirdly computed from -resource-dir in InitHeaderSearch (not run in clangDriver, thus -ccc-install-dir has no use) before rC348365. The results weren't available in clangDriver, thus the missing completion items.

Before rC348365 (will be included in clang 8 but not in clang 7) the libc++ directory (xxx/include/c++/v1) was inferred from -resource-dir.

rC348365
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -476,22 +476,6 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
   if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
       HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
     if (HSOpts.UseLibcxx) {
-      if (triple.isOSDarwin()) {
-        // On Darwin, libc++ may be installed alongside the compiler in
-        // include/c++/v1.
-        if (!HSOpts.ResourceDir.empty()) {
-          // Remove version from foo/lib/clang/version
-          StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
-          // Remove clang from foo/lib/clang
-          StringRef Lib = llvm::sys::path::parent_path(NoVer);
-          // Remove lib from foo/lib
-          SmallString<128> P = llvm::sys::path::parent_path(Lib);
-
-          // Get foo/include/c++/v1
-          llvm::sys::path::append(P, "include", "c++", "v1");
-          AddUnmappedPath(P, CXXSystem, false);
-        }
-      }

Thanks to @LeadroyaL for letting me explore his environment. Recorded here for future reference:

  • CMAKE_CXX_COMPILER:FILEPATH=/Library/Developer/CommandLineTools/usr/bin/c++
  • -resource-dir: /Library/Developer/CommandLineTools/usr/lib/clang/10.0.0
  • libc++ search directory: /Library/Developer/CommandLineTools/usr/include/c++/v1
bash-3.2$ grep CMAKE_CXX_COMOMPILER ccls/Release/CMakeCache.txt
CMAKE_CXX_COMPILER:FILEPATH=/Library/Developer/CommandLineTools/usr/bin/c++
bash-3.2$ /Library/Developer/CommandLineTools/usr/bin/c++ -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0
# /usr/bin/clang looks like a wrapper
bash-3.2$ /usr/bin/clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0

## It should also work with a custom clang
bash-3.2$ /Users/leadroyal/pllvm/r/bin/clang -print-resource-dir
/Users/leadroyal/pllvm/r/lib/clang/7.0.0
# set clang.extraArgs to -isystem /Users/leadroyal/pllvm/r/include/c++/v1

@randy3k
Copy link

randy3k commented Oct 21, 2019

If I understand correctly, the above implies that the workaround -isystem/Library/Developer/CommandLineTools/usr/include/c++/v1 is only needed for clang <v0.8. However, for some reasons, I still need it with clang v11.0 and macOS Catalina. Otherwise, the header files such as stdio.h and string.h would not be found.

cc: @MaskRay

@randy3k
Copy link

randy3k commented Oct 21, 2019

(randyimac)-~$ clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0
(randyimac)-~$ clang -v -fsyntax-only -x c++ /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -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 -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 512.4 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/Randy -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -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 11.0.0 (clang-1100.0.33.8) default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.

@alxiong
Copy link

alxiong commented Nov 20, 2019

However, for some reasons, I still need it with clang v11.0 and macOS Catalina. Otherwise, the header files such as stdio.h and string.h would not be found.

So I fix the issue by adding -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include in clang.extraArgs

@randy3k I have encountered the same issue (also Catalina), Also got the exact same result from clang -print-resource-dir and clang -v -fsyntax-only -x c++ /dev/null

So do you specify this in a .ccls file? if so , do you mind sharing with me the exact config? (doc on how to .ccls file doesn't help much)

Also do we need to specify this for every project root? Any nicer to way to work around? thanks!

@randy3k
Copy link

randy3k commented Nov 20, 2019

I didn't use .ccls because these are system wise settings. Instead, I pass

{"clang": {"extraArgs": ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"]}}

as initialization option.

Check https://github.com/MaskRay/ccls/wiki/Customization#initialization-options

Each language client may have its own way to specify initialization options. Also, initialization options can be specified on the ccls command line using the --init option.

@alxiong
Copy link

alxiong commented Nov 21, 2019

@randy3k I've tried the following and doesn't solve the issue

ccls \
--index=$HOME/path/to/projectroot \
--init='{"clang": {"extraArgs": ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"], "resourceDir": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include"}}'

Any idea why?
also may I ask why the -isystem and -isysroot at the front?

@randy3k
Copy link

randy3k commented Nov 21, 2019

Did you install the CommandLineTools at the first place?

@alxiong
Copy link

alxiong commented Nov 21, 2019

yes I did, I saw all the necessary header files at those two paths already,

@randy3k
Copy link

randy3k commented Nov 21, 2019

I didn't pass the settings to ccls via --init, but rather via the initialization options (exactly how to do it depends on your editor and cilent).

@alxiong
Copy link

alxiong commented Nov 21, 2019

@randy3k thanks for your reply, I have resolve my issue, for future reference, I use emacs, thus the following config:

  1. 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!! 😅

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

  3. 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")))
  )

🥂

@randy3k
Copy link

randy3k commented Nov 21, 2019

I'm glad that you've figured it out. I know how frustrated it could be.

@krishnakumarg1984
Copy link

The header completion does not work on my Mac. My .ccls file is as follows

%clang
-ccc-install-dir
/usr/local/Cellar/llvm/9.0.0_1/bin
-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
%cpp -stdlib=libc++

I am on neovim 0.4.0 using coc.nvim as my language-client.

Please help.

@ph0ngp
Copy link

ph0ngp commented Jan 22, 2020

@alxiong thanks for your comment, it works. I am using neovim with coc.nvim on macOS Catalina, here is my coc-settings.json for anyone who might need

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": ["c", "cpp", "objc", "objcpp"],
            "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                // see https://github.com/MaskRay/ccls/issues/191
                "clang": {
                    // from clang -v -fsyntax-only -x c++ /dev/null
                    "extraArgs": [
                        "-isystem/usr/local/include",
                        "-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
                        "-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"
                    ],
                    //From clang -print-resource-dir
                    "resourceDir": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0"
                }
            }
        }
    }
}

@neiljohari
Copy link

neiljohari commented Mar 19, 2020

@phphong

EDIT: Resolved! I just had to configure vim ALE to use CCLS, all is well now :)

I tried to follow your recommendations and headers now autocomplete just fine. But for some reason vim is complaining about not being able to find header files...

Here are the results of the commands you described:

➜ clang -v -fsyntax-only -x c++ /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -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 -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/neiljohari/dotfiles-local -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -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 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin19.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
➜ clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0

So from this output, I set my CocConfig to the following:

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": ["c", "cpp", "objc", "objcpp"],
            "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                "clang": {
                    "extraArgs": [
                      "-isystem/usr/local/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
                      "-isystem/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" 
                          ],
                    "resourceDir": "/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0"
                }
            }
        }
    }
}

Any ideas?

@findNextStep
Copy link

@phphong

EDIT: Resolved! I just had to configure vim ALE to use CCLS, all is well now :)

I tried to follow your recommendations and headers now autocomplete just fine. But for some reason vim is complaining about not being able to find header files...

Here are the results of the commands you described:

➜ clang -v -fsyntax-only -x c++ /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -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 -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/neiljohari/dotfiles-local -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -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 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin19.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
➜ clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0

So from this output, I set my CocConfig to the following:

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": ["c", "cpp", "objc", "objcpp"],
            "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                "clang": {
                    "extraArgs": [
                      "-isystem/usr/local/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
                      "-isystem/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" 
                          ],
                    "resourceDir": "/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0"
                }
            }
        }
    }
}

Any ideas?

maybe you can try brew install llvmand config like below

{
    "clang": {
        "extraArgs": [
             "-isystem",
             "/usr/local/opt/llvm/include/c++/v1",
        ],
        "resourceDir": "/usr/local/opt/llvm/lib/clang/9.0.1"
    },
}

@arthurkiller
Copy link

@phphong

EDIT: Resolved! I just had to configure vim ALE to use CCLS, all is well now :)

I tried to follow your recommendations and headers now autocomplete just fine. But for some reason vim is complaining about not being able to find header files...

Here are the results of the commands you described:

➜ clang -v -fsyntax-only -x c++ /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -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 -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/neiljohari/dotfiles-local -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -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 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin19.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
➜ clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0

So from this output, I set my CocConfig to the following:

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": ["c", "cpp", "objc", "objcpp"],
            "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                "clang": {
                    "extraArgs": [
                      "-isystem/usr/local/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
                      "-isystem/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" 
                          ],
                    "resourceDir": "/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0"
                }
            }
        }
    }
}

Any ideas?

hey, could u pls post your vim ale ccls configurations here?
thx

@neiljohari
Copy link

neiljohari commented Mar 31, 2020

@phphong
EDIT: Resolved! I just had to configure vim ALE to use CCLS, all is well now :)
I tried to follow your recommendations and headers now autocomplete just fine. But for some reason vim is complaining about not being able to find header files...
Here are the results of the commands you described:

➜ clang -v -fsyntax-only -x c++ /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -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 -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/neiljohari/dotfiles-local -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -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 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin19.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
➜ clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0

So from this output, I set my CocConfig to the following:

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": ["c", "cpp", "objc", "objcpp"],
            "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                "clang": {
                    "extraArgs": [
                      "-isystem/usr/local/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
                      "-isystem/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include",
                      "-isystem/Library/Developer/CommandLineTools/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
                      "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" 
                          ],
                    "resourceDir": "/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0"
                }
            }
        }
    }
}

Any ideas?

hey, could u pls post your vim ale ccls configurations here?
thx

Sure! Here's the relevant part of my vimcrc on my dotfiles rep: https://github.com/neiljohari/dotfiles/blob/2770fb1a211141ecbdf30b7c5f89603ab440b774/vimrc.local#L91

@ssh352
Copy link

ssh352 commented Apr 23, 2020

mark same issue

@neiljohari
Copy link

neiljohari commented May 21, 2020

edit: resolved by workaround in #622 (comment) (hopefully we can find a more reasonable solution though!)

Somehow, this issue has randomly come back up. I've been investigating for a bit now, very surprised.

The output of clang -v -fsyntax-only -x c++ /dev/null and clang -print-resource-dir remains the same as when it was previously working. The issue is not ALE (like I had mistaken last time); I can verify this because I forced VSCode to use CCLS as well, and it has the same issues with being unable to find iostream and such headers.

Any ideas on debugging this? The only changes have been brew upgrades, which I'm not sure but maybe node and npm had version changes? They still fit the requirements, and I think they are linked into my path so CCLS should be able to find it.

Very strange issue to randomly appear.


I'll post findings here:

  1. If I get rid of all the ccls init options, I can no longer jump to the headers that claim to not be found. I see the iostream header at /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream, so it really should be able to find it...

  2. The minimal test described in the wiki leads to an error for only the first include (system C header):

// a.cc
// system C header, usually in /usr/include
#include <stdio.h>
// system C++ header. The location varies among distributions, e.g. /usr/include/c++/{6,7.2.1}
#include <new>
// In Clang resource directory lib/clang/7.0.0, lib/clang/7.0.0/include/stddef.h
#include <stddef.h>

@krishnakumarg1984
Copy link

Same issue occurs for me as well. Frustrating.

@arthurkiller
Copy link

arthurkiller commented Oct 16, 2020

@krishnakumarg1984 have you tried those solutions above?

It works for me

@jintaoyugithub
Copy link

@alxiong thanks for your comment, it works. I am using neovim with coc.nvim on macOS Catalina, here is my coc-settings.json for anyone who might need

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": ["c", "cpp", "objc", "objcpp"],
            "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                // see https://github.com/MaskRay/ccls/issues/191
                "clang": {
                    // from clang -v -fsyntax-only -x c++ /dev/null
                    "extraArgs": [
                        "-isystem/usr/local/include",
                        "-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
                        "-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"
                    ],
                    //From clang -print-resource-dir
                    "resourceDir": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0"
                }
            }
        }
    }
}

Oh god! Finally, that works!!!!!! thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests