问题
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 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
#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.
回答1:
In your .ycm_extra_conf.py
add your regular preprocessor flags, e.g.:
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',
]
来源:https://stackoverflow.com/questions/24438211/youcompleteme-header-files