[cfe-dev] Extracting the include tree from a source file

Nico Weber thakis at chromium.org
Mon Nov 15 15:33:12 PST 2010


On Mon, Nov 15, 2010 at 9:27 PM, Bertjan Broeksema <broeksema at kde.org> wrote:
> 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?

Hm, this _might_ be because clang comes with a few standard headers,
see clang/lib/Headers. Maybe clang adds these to the search path
somehow. Adding a gentoo-specific include path is the correct fix in
this case.

>
> Cheers,
>
> Bertjan
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list