[cfe-dev] Include Default C++ paths

David Blaikie dblaikie at gmail.com
Wed Oct 17 09:39:30 PDT 2012


On Wed, Oct 17, 2012 at 9:29 AM, madil90 <madil90 at gmail.com> wrote:
> Hi,
>    I am trying to parse a C++ code but clang doesn't recognize the C++
> types. Consider the following code
>
> #include <iostream>
> #include <string>
>
> int main()
> {
>     string str;
> }
>
> clang gives an error at <iostream> and doesn't recognize the string type. To
> enable C++, I did "langOptions.CPlusPlus=1" and the code recognizes custom
> C++ classes. So how do I include default C++ paths?

I assume you're using clang as a library, rather than actually going
through the clang driver? The driver's where all (most) of the header
search logic is. You can extract the paths by simply asking clang what
command it used to invoke the frontend (I forget offhand, but there is
a verbose/print-commands option to clang) & just pass those in. But if
you want to make a tool using clang as a library & have the same
header/lib discovery that the clang command line program has, you'd
need to duplicate or reuse the logic in the driver.

- David



More information about the cfe-dev mailing list