-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
macOS Mojave: Include clang header files when using compile_commands.json #3159
Comments
So from all the documentation I've read, this issue is that LibClang doesn't know where its STL is, while Clang does. There was some hack done to get this working for macOs. AFAICT, it looks like this isn't working for Mojave. I don't know where this code exists in YCM, or I might try to submit a PR. Of course I lost the issue where Valloric mentions this issue. I'll keep looking for it... |
Ah it's here: #303 (comment) |
Also, this is sort of a unique problem for me. I have a custom installed clang (from MacPorts) in /opt/local, so the flags I need to get added are: /opt/local/libexec/llvm-6.0/include/c++/v1 The problem is (obviously) that I'm using compile_commands.json, so even the usual hack of just assuming where the internal libs are won't be correct for me. This isn't so much a problem with iostream, but it becomes a problem when I want to build with advanced C++17 or C++2a with the latest branch of clang. I think I can work around this by manually including the paths in my CMake so they show up in compile_commands.json, but this is... still a workaround. Why not try at least to use my compile_commands.json to use my compiler (in this case, I know not all cases will have a compiler available) in order to figure out what those default include paths are? The full path to the clang I'm using is there, so we have all the info we need. We could scrape the -v output (https://stackoverflow.com/a/23658940) and get (and cache?) the paths we need to add so that libclang knows where to look. Yeah, it's ugly and I wish libclang would come with clang's STL and do the includes just like clang does, but... it would work... Thoughts? |
It's a little more complicated than that, but essentially that is correct.
I love this. I really think Apple just likes to shuffle stuff around every few years just to screw with libclang users like we are.
Take a look at
I agree that it is a workaround. However, sucessfully finding the user's headers on all OS's is hard and so has been mostly up to users to do that for now.
This is an open question in ycm-core/ycmd#853. So far we are leaning towards not caching, because at worst it takes 40ms to get the clang output and process it.
This is an interesting point. We might want to allow users to somehow tell us which clang, not just aim for Bottom line is that you should definitely give ycm-core/ycmd#853 a try and report what you find. |
I have same problem, after I have updated the macOS. I found the option The function |
@chrisniael I think the proper thing to do would be to fix _SysRootSpecifiedIn, yes? Naively, I think it's failing on my system due to a unicode issue. I may fix this and submit a PR... FYI, the workaround does work. @bstaletic Thanks for the info. I think I will request the ability to specify Clang, or deduce Clang from compile_commands.json in that thread. |
Just a note about changing |
+1, for Chromium Project, in both macOS 10.13 & 10.14. Thanks @joelfrederico |
I should have been more specific, my workaround works. Modifying CMake to include the paths clang includes automatically does put them in the compile_commands.json, which ycm used to find the files. |
My previous comment was really vague. I was refering to removing the |
The '-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' option added in compile_commands.json by cmake would prevent ycmd from finding std library such as iostream. Currently I just removed it like what @chrisniael said as a workaround. Maybe there're better solutions. |
My experience is similar to @xuyuheng's above. I'm using YCM on MacOS 10.13.6 with Chromium where we have a custom .ycm_extra_conf.py script that ends up adding:
By modifying
as a workaround, I was able to get YCM working again. |
[READY] Fix system headers search on macOS We can't rely on upstream libclang to find the system headers on macOS because it ignores the `-resource-dir` flag and use the current working directory to find the builtin includes instead, which fails since they are in a different place (in the `clang_includes` folder). Furthermore, it's unable to find the framework headers on macOS 10.14 without setting the sysroot. So, we try to reproduce the logic used by Apple Clang to find the system headers by looking at the output of the command ```sh clang++ -x c++ -E -v - ``` which prints the list of system header directories and by reading the source code of upstream Clang. This code probably differs from the latest version of Apple Clang but still gives an idea of how it works. The builtin includes have been moved to `clang_includes/lib/clang/version/include` to replicate the structure used by upstream libclang. This could be useful if we decide to include the libc++ standard library which would be copied to `clang_includes/include/c++/v1`. Clangd would then be able to find the libc++ headers with `-resource-dir` sets to the `clang_includes/lib/clang/version` folder (not libclang because of the reason given above). Fixes ycm-core/YouCompleteMe#3159. Fixes ycm-core/YouCompleteMe#3249. Fixes ycm-core/YouCompleteMe#3286. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/1172) <!-- Reviewable:end -->
Issue Prelude
Please complete these steps and check these boxes (by putting an
x
insidethe brackets) before filing your issue:
Frequently Asked Questions section.
about to report and couldn't find an answer to my problem. (Example Google
search.)
vim --version
.:YcmDebugInfo
.the
:YcmToggleLogs
command.version) I am using.
my issue, including what I expected to happen and what actually happened.
of
install.py
(orcmake
/make
/ninja
) including its invocationthat any help I receive is a selfless, heartfelt gift of their free time. I
know I am not entitled to anything and will be polite and courteous.
actually perform all of these steps.
Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.
Issue Details
I included C++ headers.
Locate the headers, understand the stuff in them.
Couldn't find the headers
Diagnostic data
Output of
vim --version
Output of
YcmDebugInfo
Printing YouCompleteMe debug information...
-- Client logfile: /var/folders/8k/6z0xcptd00gbx6mgqvr0xgy00000gn/T/ycm_UcoIcf.log
-- Server Python interpreter: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
-- Server Python version: 2.7.15
-- Server has Clang support compiled in: True
-- Clang version: clang version 6.0.0 (tags/RELEASE_600/final)
-- No extra configuration file found
-- C-family completer debug information:
-- Compilation database path: /Users//Dev/Testing
-- Flags: [u'/opt/local/bin/clang++-mp-6.0', u'-isysroot', u'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Dev
eloper/SDKs/MacOSX10.14.sdk', u'-std=gnu++14', u'-resource-dir=/Users//.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../
clang_includes', u'-fspell-checking']
-- Translation unit: /Users//Dev/Testing/src/main.cpp
-- Server running at: http://127.0.0.1:55432
-- Server process ID: 10731
-- Server logfiles:
Contents of YCM, ycmd and completion engine logfiles
OS version, distribution, etc.
macOS Mojave 10.14
Output of build/install commands
The text was updated successfully, but these errors were encountered: