[cfe-dev] Extracting the include tree from a source file
Bertjan Broeksema
broeksema at kde.org
Mon Nov 15 12:27:59 PST 2010
Bertjan Broeksema wrote:
> Nico Weber wrote:
>
>> On Mon, Nov 15, 2010 at 8:33 PM, Bertjan Broeksema
>> <broeksema at kde.org> wrote:
>>> Hi,
>>>
>>> Nico Weber wrote:
>>>
>>> Thanks for the quick reply!
>>>
>>>> Hi,
>>>>
>>>> Call InitializePreprocessor to add defines. To fix the crash, add
>>>> calls to BeginSourceFile()/EndSourceFile() (see
>>>> https://github.com/nico/clangtut/blob/master/tut03_pp.cpp ).
>>>
>>> Yes, I'm a step closer now, it indeed doesn't crash anymore when an
>>> error occurs. However, I still have the problem that system includes are
>>> not found. In this particular case stddef.h. I am somewhat assuming that
>>> it shouldn't be needed to add paths like:
>>>
>>> /usr/include/linux (for stddef.h)
>>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include
>>>
>>> clang++ (the command line tool), seems to have these paths available as
>>> it is able to preprocess the same file I'm testing with, without
>>> complaining about not finding stddef.h
>>
>> All these are added in InitHeaderSearch::AddDefaultCIncludePaths()
>> and friends in lib/Frontend/InitHeaderSearch.cpp. Maybe step through
>> that code for your binary and for clang and check which branches are
>> taken in both cases.
>
> Found two problems, the first was obvious: I didn't set any language
> enabled in LanguageOptions -> langOption.CPlusPlus = true; Doh!
>
> The second, I've a recent Gentoo system and the following path is missing
> in InitHeaderSearch.cpp:
>
> // Gentoo amd64 gcc 4.4.4
> AddGnuCPlusPlusIncludePaths(
> "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4",
> "x86_64-pc-linux-gnu", "32", "", triple);
>
Replying to myself, this latter doesn't explain the problem, as it does work
with clang++. The first results in a lot of "ignoring nonexistent directory"
messages so I'm at least a step closer, but there must be something else I'm
overlooking. Maybe more languageOptions must be enabled?
Cheers,
Bertjan
More information about the cfe-dev
mailing list