Compiler arguments for clang_parseTranslationUnit

Where can I find detailed information about the accepted options for the "command_line_args" parameter of the clang_parseTranslationUnit function ?

In particular, it appears that by default this function picks up flags (include search paths, macros) from the system compiler installed on my platform (Fedora 14). How can I override that ? For example, may I invoke this function to use flags for a non-system compiler ? (I'm in particular interested into a variety of cross-compilers I have installed.)

Also, how can I choose the language and language flags to be used for lexing and parsing ("C", "C99", "C++", etc.) ?

Thanks,
         Stefan

They are the same as the command-line driver.

Chip

I think the idea is that you just pass in argc and argv to that function so that your tool can be used as a drop-in replacement for a real compiler.

I think the idea is that you just pass in argc and argv to that function so that your tool can be used as a drop-in replacement for a real compiler.

Yes, this is the intent.

And the best place to look for documentation on the command-line options Clang accepts is… the GCC documentation. Clang doesn’t have a user manual describing all of its command-line options :slight_smile:

  • Doug

Fair enough. But which GCC would that be ? Different versions use different defaults. Can I change what compiler Clang targets / emulates ?
For example, I have a Cell cross-compiler installed on my laptop (giving me 'ppu-g++' and 'spu-g++'). How can I make Clang use their sysroots and related flags ?

To illustrate my use-case a little:

I'm working on a portable library that targets different platforms. Depending on how I compile it, different backends are picked up. I'd like to be able to process that library with Synopsis to "see" all the active backends in the generated documentation, which requires it to emulate the different compilers I'd normally compile the library with.

Thanks,
         Stefan

The *real* answer would be if this actually existed:

  http://clang.llvm.org/UniversalDriver.html

However, you'll likely need to use -nostdinc/-nostdinc++ and a bunch of -isystem options to teach Clang to look in the right include directories.

  - Doug

I see, thanks. How are the built-in macros determined that clang defines ? Can I disable them with something similar to -nostdinc ?

The current Synopsis logic allows users to specify a compiler to emulate.
If this is a GCC variant, I query the compiler itself for macros and headers (via `g++ -E -v -dD ...`)
If it is a MSVC compiler, I use hardcoded sets of flags.

This logic requires that the parser then doesn't add its own set of macros, as those may actually conflict with what I feed in from the above.

Thanks,
         Stefan

However, you'll likely need to use -nostdinc/-nostdinc++ and a bunch of -isystem options to teach Clang to look in the right include directories.

I see, thanks. How are the built-in macros determined that clang defines ? Can I disable them with something similar to -nostdinc ?

No, those depend on the target (which you can hack with -ccc-host-triple) and on language-setting flags.

The current Synopsis logic allows users to specify a compiler to emulate.
If this is a GCC variant, I query the compiler itself for macros and headers (via `g++ -E -v -dD ...`)
If it is a MSVC compiler, I use hardcoded sets of flags.

This logic requires that the parser then doesn't add its own set of macros, as those may actually conflict with what I feed in from the above.

I don't have a good solution for this. Clang knows how to emulate other compilers to some extent; you're probably better off using -ccc-host-triple to pick an appropriate target.

  - Doug