[cfe-dev] Using "-x c++" with clang_parseTranslationUnit()

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Mar 20 11:22:55 PDT 2011


What was happening was when creating the final argument list for clang, the given arguments were put after the input_file like this:

<input_file> ... -x c++ ..

in which case -x had no effect. This is fixed now in r127971. (Just FYI, it would not happen if you had passed the input file inside the array of args instead of using the input_file parameter).

-Argiris

On Mar 19, 2011, at 3:20 PM, Stefan Seefeld wrote:

> On 2011-03-19 18:13, Argyrios Kyrtzidis wrote:
>> Could you post some code?
> 
> Here is the relevant snippet ('bpl' is an alias to boost::python, and cpp_flags is a Python list with additional compiler flags, such as -I..., -D..., etc.):
> 
>  char const **args = new char const*[bpl::len(cpp_flags) + 2];
>  args[0] = "-x";
>  args[1] = "c++";
>  for (size_t i = 0; i != bpl::len(cpp_flags); ++i)
>    args[i + 2] = bpl::extract<char const *>(cpp_flags[i]);
> 
>  CXIndex idx = clang_createIndex(0, 1);
>  CXTranslationUnit_Flags flags = CXTranslationUnit_DetailedPreprocessingRecord;
>  CXTranslationUnit tu =
>    clang_parseTranslationUnit(idx, input_file,
>                   args,
>                   bpl::len(cpp_flags) + 2,
>                   0,  // unsaved_files
>                   0,  // num_unsaved_files
>                   flags);
> 
> 
> Running this on a C++ source file with extension '.h' will first warn about unused '-x c++', and then cause an error since its header search path doesn't include standard C++ headers.
> 
> (I'm in fact trying to parse clang code itself to generate a cross reference via Synopsis.)
> 
> Thanks,
>        Stefan
> 
> -- 
> 
>      ...ich hab' noch einen Koffer in Berlin...
> 





More information about the cfe-dev mailing list