Anda di halaman 1dari 2

Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards.

Listen
now

YouCompleteMe, header files


Asked 5 years, 4 months ago Active 2 years, 4 months ago Viewed 8k times

I am working with some C++ header files using YouCompleteMe. The header file does not include
all the other header files that it needs in order to find all the classes it is using. Without modifying the
7 header file, can can I modify my .ycm_extra_conf.py file to have clang know about the additional
header files it needs?

As an example, suppose I have three files "A.h", "B.h", and "C.cc".

C.cc
4

#include "A.h"
#include "B.h"

A.h

class A {};

B.h

class B : A {};

The B include file cannot compile on it's own, but C.cc will compile correctly because it includes
things in the right order. However, if I open B.h on it's own, it will complain about A not being
defined.

I know that C.cc compiles correctly, so how do I tell YCM when opening B.h to compile it in the
same context it would use for C.cc? Flags seem to be insufficient to tell YCM how to compile the file,
as it needs to be compiled with C.cc.

c++ vim

edited Jun 27 '14 at 18:18 asked Jun 26 '14 at 19:03


archgoon
793 1 10 17

1 What does your last sentence mean? – sehe Jun 26 '14 at 22:14

Hi sehe, I've updated the comment to more clearly explain the issue. Thanks! – archgoon Jun 27 '14 at
18:59

1 Answer
In your .ycm_extra_conf.py add your regular preprocessor flags, e.g.:

7 flags = [
'-Wall',
'-Wextra',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
'-DUNIT_TESTS',
'-std=c++11',
'-x', 'c++',
'-isystem', '/home/sehe/custom/boost',
'-isystem', '/usr/lib/gcc/x86_64-linux-gnu/4.8/include',
'-I', 'src',
'-I', 'include',
'-isystem', '/usr/include',
'-isystem', '/usr/local/include',
]

answered Jun 26 '14 at 22:16


sehe
289k 36 366 491

Anda mungkin juga menyukai