Sunteți pe pagina 1din 10

Learn Git and GitHub without any code!

Using the Hello World guide, you’ll start a branch, write comments, and open a pull request.

Read the guide

ycm-core / YouCompleteMe

Using default .ycm_extra_conf.py, the standard c++11 New issue

headers are not found. #303


Closed cebrusfs opened this issue on May 8, 2013 · 70 comments

cebrusfs commented on May 8, 2013 Assignees

No one assigned
I set g:ycm_global_ycm_extra_conf in my vimrc.

Labels
let g:ycm_global_ycm_extra_conf =
'~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' None yet

Projects
After including a c++11 header unordered_map , I got 'unordered_map' file not found reported by
Syntastic plugin. None yet

After adding
Milestone

No milestone
'-I',
'/usr/include/c++/4.2.1/tr1/'

in flags in .ycm_extra_conf , now my problem is solved. 33 participants

In default .ycm_extra_conf , the environment didn't include any c++11 headers, but the argument -
std=c++11 still in flags ?

I think it's strange. Something should be wrong.

I use the mac os 10.7.5 (Lion) and the following is report by :YcmDebugInfo command, hope it helps. and others

-- Flags for /Users/cebrusfs/test.cpp loaded from


/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py:
-- ['-Wall', '-Wextra', '-Werror', '-Wc++98-compat', '-Wno-long-long', '-Wno-variadic-
macros', '-fex
ceptions', '-DNDEBUG', '-DUSE_CLANG_COMPLETER', '-std=c++11', '-x', 'c++', '-isystem',
'/Users/cebru
sfs/.vim/bundle/YouCompleteMe/cpp/ycm/../BoostParts', '-isystem',
'/System/Library/Frameworks/Python
.framework/Headers', '-isystem',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/../llvm/include'
, '-isystem',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/../llvm/tools/clang/include', '-I',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/.', '-I',
'/Users/cebrusfs/.vim/bundle/YouComple
teMe/cpp/ycm/./ClangCompleter', '-isystem',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/./tes
ts/gmock/gtest', '-isystem',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/./tests/gmock/gtest/
include', '-isystem',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/./tests/gmock', '-isystem',
'/Users/cebrusfs/.vim/bundle/YouCompleteMe/cpp/ycm/./tests/gmock/include', '-I',
'/Users/cebrusfs/.
vim/bundle/YouCompleteMe/autoload/../python/clang_includes']
-- Has Clang support compiled in: True
-- clang version 3.2 (tags/RELEASE_32/final)

pedrovanzella commented on May 8, 2013

This didn't work for me.


It keeps saying that random doesn't exist.

Also, I get the same thing as #192.

oblitum commented on May 8, 2013 Contributor

I've gone through this too and assumed that the current behavior won't try check clang default include
directories from compiler flags as -std=libc++ and -std=c++11 for example. They can be verified
with echo | clang -std=c++11 -stdlib=libc++ -v -E -x c++ -

pedrovanzella commented on May 8, 2013

I found out that YCM keeps adding '-I', '/Users/pedrovanzella


/dotfiles/vim/bundle/YouCompleteMe/autoload/../python/clang_includes' to the flags, and this
makes compilation fail.

This works fine:

clang++ hello.cpp -Wall -Wextra -Werror -Wno-long-long -Wno-variadic-macros -


fexceptions -DNDEBUG -DUSE_CLANG_COMPLETER -std=c++11 -stdlib=libc++ -x c++ -c

This fails:

clang++ hello.cpp -Wall -Wextra -Werror -Wno-long-long -Wno-variadic-macros -


fexceptions -DNDEBUG -DUSE_CLANG_COMPLETER -std=c++11 -stdlib=libc++ -x c++ -c -I
/Users/pedrovanzella/dotfiles/vim/bundle/YouCompleteMe/autoload/../python/clang_includes

I stripped .ycm_extra_conf.py bare, but YCM keeps adding this to the flags.

pedrovanzella commented on May 8, 2013

I found this: https://gist.github.com/locojay/4950253

And it works wonders.

Basically, the only include flag you really need is '-isystem', '/usr/lib/c++/v1', .

This should also fix #305.

1
Valloric commented on May 8, 2013 Member

The .ycm_extra_conf.py file linked to from the README is an example file, it's not supposed to cover
everything for everyone. The flags that are there by default work for YCM; you're supposed to make an
extra conf file yourself that best fits your project (usually by modifying the example file). The easiest way
is often to just take the same flags you're passing to gcc/clang when you compile your source files.

YCM adds the path to clang_includes because without those clang-specific includes, semantic code
completion would be slow. Clang needs to be able to see the files in that folder to operate correctly, no
matter what source code you're compiling.

Valloric closed this on May 8, 2013

oblitum commented on May 9, 2013 Contributor

@Valloric Does that answer whether it's assumed as issue or not for YCM not to be able to
automatically include default included header files (which for flags -std=c++11 and -stdlib=libc++
for example, can be easily verified with echo | clang -std=c++11 -stdlib=libc++ -v -E -x c++
- )?.

Just passing the same flags you're passing to gcc/clang when you compile your source files won't lead
to working completion, one must know which headers the compiler include by default for a given set of
flags, and include those by hand (IIRC, I had to list even simple /usr/local/include ).

Valloric commented on May 9, 2013 Member

@oblitum Yes, that is troubling... I still can't understand why freaking libclang won't use its default
header search paths for code completion like it would for normal compilation. I guess we need a way to
pull out the default search paths and append them. Any ideas? We can't call the clang binary because it
may not exist on the system. The solution would have to be based on pure libclang.

I know some Clang developers; I'll ask what they think about this.

oblitum commented on May 12, 2013 Contributor

@Valloric Sadly, from libclang solely, I've no idea... But, should this issue just be kept closed? At last,
this seems a good place for solutions to be brought and, this is indeed a thing newcomers may stumble
upon recurrently.

oblitum commented on May 12, 2013 Contributor

If not reopened, I think it's a good item for FAQ (I've not checked whether there's one such item already).

Valloric reopened this on May 12, 2013

Valloric commented on May 12, 2013 Member

Reopening until we figure this out fully.


pedrovanzella commented on May 15, 2013

Could we include a few example ycm_extra_conf.py in the README? This sounds like a sensible
solution.

pedrovanzella referenced this issue on May 15, 2013

Use completions from C header files in C++ projects #312 Closed

xunfan commented on May 31, 2013

I just have the similar problems and now I have solved them. If standard headers are not found, the
good tool to debug is to use :YcmDiages in vim to see the bug information. You will see what errors are
there, such as in xxx.h, yyy.h cannot find. Then you will find yyy.h and add the correct include path to the
.ycm_extra_conf.py.

Another thing is sometimes the auto-completion cannot find members of a class I defined. The problem
is there are errors in :YcmDiages. It seems sometimes if there are errors, ycm stop auto-competion for
you...

Valloric referenced this issue on Jul 12, 2013

using compile_commands.json cannot find system includes #445 Closed

Valloric referenced this issue on Oct 8, 2013

no stl headers can be found #572 Closed

sven-strothoff commented on Oct 30, 2013

On OS X 10.9 with Xcode 5.0.1 you can add

-
isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr

to your compile flags to get completion for the STL until there is a proper fix for this issue.
This works if libClang from the Xcode Command Line Tools, i.e.
/Library/Developer/CommandLineTools/usr/lib/libclang.dylib is used as external libClang ( -
DEXTERNAL_LIBCLANG_PATH ) when building YCM.

The STL include path can be obtained with (as suggested by @oblitum):
echo | clang -std=c++11 -stdlib=libc++ -v -E -x c++ -

Valloric commented on Nov 18, 2013 Member

I've mentioned this issue in the FAQ along with a workaround. I'm looking into a more long-term fix as
well, sit tight.

ofan commented on Nov 21, 2013

I'm writing this just in case someone else runs into the same problem I hit:
I got YCM (partially) working but when I run :YcmDiags , it gave me a list of errors, but syntax and
semantic checking seem partially working
error: no member named int8_t in the global namespace

It's in the cstdint header, apparently clang cannot find the proper stdint.h header, even if I add
'/usr/include' in the search directories. The problem is the order of '-I /usr/include' and '-I
/opt/local/libexec/llvm-3.3/lib/c++/v1' , I simply move the '-I /usr/include' parameter to the
front, then the problem is solved, and YCM is now working like a charm.

tioover referenced this issue on Dec 11, 2013

Syntastic cannot check c++ #718 Closed

Valloric referenced this issue on Dec 18, 2013

When using json db for c++ completion headers do not compile #735 Closed

bfrg commented on Dec 28, 2013

I'm having the same issues on my linux machine, too. Unfortunately, the suggested workarounds don't
work for me. It's not only the std headers that are not found but also other stuff like eigen3. But for some
reasons boost headers are found by default without specifying any additional include directories.

Valloric referenced this issue on Jan 2, 2014

YcmDiags complains about /usr/lib/llvm- Closed

3.4/lib/clang/3.4/include/module.map #749

baronleonardo commented on Jan 25, 2014

Comment out '-Wc++98-compat' from your ycm_extra_conf.py

marchtea referenced this issue on Feb 1, 2014

mac mavericks, /usr/include/module.map|36 col 14 error| header 'float.h' Closed

not found #809

This was referenced on Apr 2, 2014

Fix libclang's #include search path #910 Merged

YCM doesn't recognize size_t in C++ and marks them as an error. #922 Closed

davits commented on Apr 4, 2014 Contributor

I have fixed my standard header version incompatibility problems by turning off clang's default standard
header paths and adding correct ones.
Hope this will be helpful.

'-nostdinc++',
'-isystem', '/path_to_gcc/include/c++/4.7.2',
'-isystem', '/path_to_gcc/include/c++/4.7.2/x86_64-redhat-linux',
'-isystem', '/path_to_gcc/include/c++/4.7.2/backward',

2
Valloric referenced this issue on May 8, 2014

Incorrect warning "no newline at end of file" #950 Closed

50 hidden items
Load more…

puremourning commented on Apr 8, 2016 Member

I just know you need those flags on RH because I use it every day.

On 8 Apr 2016, at 10:00, dragonxlwang notifications@github.com wrote:

Yes, I have read through (at least I believe) the readme, and the closed thing that i have across
which brought me here is this FAQ. However, since my problem is not only C++ but also C, I just
wanna make sure that the fix still applies to me (by using echo | clang -v -E -x c++ -). I used that
workaround and so far so good...

However, didn't see anything talking about red hat or specifically devtoolset-2. Would appreciate if
you point to me :)


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

dragonxlwang commented on Apr 8, 2016

Thanks!

macskay commented on Apr 21, 2016 • edited

For me the only way to get and std::cout / std::endl working was to add

'-I', '/usr/include/c++/5/'
or
'-I', '/usr/include/c++/5.3.1/'

and the -std=c++11 flag inside my .ycm_extra_conf.py

Using Ubuntu MATE 16.04, g++ 5.3.1 (Ubuntu 5.3.1-14ubuntu2) 20160413

Hope this helps

dragonxlwang commented on Apr 21, 2016

IMHO there might be a potential problem using -I flag instead of -isystem

jagerman commented on May 24, 2016 • edited

On Linux (at least Ubuntu, probably others as well), the libclang from llvm.org is now working fine. It
will find paths to the standard library without issues.
@Valloric Can you confirm that this is still the case with libclang 3.8? I've noticed the problem showing
up recently in Debian testing, and after investigating a little, it seems to coincide with an upgraded
version of Debian's ycmd, which started being built against clang 3.8 around the middle of April—and,
IIRC, that's around the time standard headers stopped being included properly.

I installed Ubuntu 16.04 (which also has ycmd built against clang 3.8) into a virtual machine to test it--
same issue: standard headers are not found by default.

I can apply the workaround to get it to work, but that's a nuisance, particularly since the workaround
needs to be updated in every project every time stdlibc++ gets a major version upgrade, which is going
to be happening more frequently with GCC's new versioning scheme.

We want to make the 99% use-case easy and pain-free; sometimes that means that the 1% use-
case is more difficult and it's a price we're willing to pay.

The current situation on Debian/Ubuntu seems to be failing this goal: even a simple C++ hello world
doesn't work properly. If this is something Debian and Ubuntu have screwed up in libclang-3.8,
responsibility for fixing it obviously goes there, but if this is an upstream llvm change, this really needs a
fix either in ycm or upstream llvm.

bijancn pushed a commit to bijancn/YouCompleteMe that referenced this issue on Jul 26, 2016

Auto merge of ycm-core#303 - micbou:python-restart-server, r=Valloric … 9164e2e

agauniyal commented on Aug 17, 2016 • edited

Not working anymore with libclang 3.8. I've tried various conf, '-isystem' as well as '-I' and putting
flags from echo | clang -v -E -x c++ -

puremourning commented on Aug 17, 2016 Member

If you have a new problem, please raise a new issue, following the instructions in CONTRIBUTING.md

Hexcles referenced this issue on Sep 12, 2016

Linux also needs heuristic workaround for libclang default include paths Closed

#2330
8 of 11 tasks complete

Hexcles commented on Sep 12, 2016

Hi @puremourning , I filed #2330 for the new problem (the root problem is still exactly the same
though) as reported by @jagerman (and I can also confirm it), in particular discussing the need for
Linux workaround similar to the macOS one. Cheers.

acherub pushed a commit to acherub/dotfiles that referenced this issue on Sep 20, 2016

Some plugins added … 8bb77ea

cranehuang referenced this issue on Oct 11, 2016

Spacemacs Rocks(3): 打造C/C++ IDE #3 Open

leofang added a commit to leofang/YCM-Generator that referenced this issue on Oct 23, 2016

Add the workaround from cpradog/.ycm_extra_conf.py@aad88d … 062f14b


leofang added a commit to leofang/YCM-Generator that referenced this issue on Oct 23, 2016

Add the workaround from https://gist.github.com/cpradog/aad88d51001ea… 91cc956


leofang added a commit to leofang/YCM-Generator that referenced this issue on Oct 23, 2016

Add the workaround from https://gist.github.com/cpradog/aad88d51001ea… 6f044a6


hansonw referenced this issue on Dec 6, 2016

Clang system headers are not included by default #916 Open

storluffarn commented on Apr 22, 2017

To anyone who came here searching for answers to how to include eigen (there was this post by @bfrg
from 2013), the correct addition to the ycm_extra_conf.py file is: '-isystem', '/usr/include/eigen3', as of
today (early 2017).

riveridea commented on May 2, 2017

With
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1'

I still cannot let ycm to find c++ STL names, though all the C++ STL files are in the above directory.
Don't know why. I am using MAC running osx 11.

riveridea commented on May 2, 2017

This is the result after I run


echo | clang -v -E -x c++ -

#include "..." search starts here:

#include <...> search starts here:


/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/
v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0
.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.
12.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.
12.sdk/System/Library/Frameworks (framework directory)

vheon commented on May 3, 2017 Collaborator

@riveridea you should try to add

'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/.

'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/.
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/inclu

'-isystem',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacO

so all except the one with (framework directory) at the end.

riveridea commented on May 4, 2017

@vheon It still does not work after I add all the possible paths as you suggested.

dolphin-zs commented on Jun 7, 2017 • edited

I fix this problem by adding the following lines


'-isystem', '/usr/include/c++/4.8', '-isystem', '/usr/include/x86_64-linux-gnu/c++/4.8',
Only providing the path to "iostream" file is not enough, there is an 'include "bits/c++config.h"' statement
in "iostream" file, while "bits/c++config.h" is located at '/usr/include/x86_64-linux-gnu/c++/4.8/'.

Running :YcmDiags and you will know what's going wrong

dillon4287 referenced this issue on Mar 29, 2018

YouCompleteMe with eigen3, incorrect syntax highlighting #2965 Closed

IngoHeimbach referenced this issue on May 31, 2018

Libclang does not find its include directory on Linux #52 Open

proudlily commented on Jun 11, 2018

@macskay hello,where did i to use "'-I', '/usr/include/c++/5/'"? i meet the same problam .

proudlily commented on Jun 11, 2018

@macskay hi,i got it .in the ycm_extra_conf.py

joelfrederico referenced this issue on Sep 26, 2018

macOS Mojave: Include clang header files when using Closed

compile_commands.json #3159
8 of 12 tasks complete

oblitum referenced this issue on Nov 9, 2018

Support for compile_flags.txt? #110 Closed

s4y referenced this issue on Feb 22

Fix system header search paths on macOS for Objective-C++, too. #1193 Merged
zzbot added a commit to ycm-core/ycmd that referenced this issue on Feb 23

Auto merge of #1193 - s4y:objcpp-needs-fixed-header-search-paths- Verified 6d8ddd5


too,… …

S-ar putea să vă placă și