[cfe-dev] ClangTool and the usual commandline options

Russell Wallace via cfe-dev cfe-dev at lists.llvm.org
Sat Dec 12 20:03:35 PST 2015

I'm writing a program that uses ClangTool to parrse C++ code; per the
tutorials, the main module looks as below.

It works for a single file, but more complex inputs require the usual
commandline options to set include path, Microsoft compatibility mode et
cetera, and by default you only get a few options like -help and -version.

How do you get the usual set of commandline options that clang has?

// Apply a custom category to all command-line options so that they are the
// only ones displayed.
static cl::OptionCategory MyToolCategory("my-tool options");

// CommonOptionsParser declares HelpMessage with a description of the common
// command-line options related to the compilation database and input files.
// It's nice to have this help message in all tools.
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);

int main(int argc, const char **argv) {
  std::set_new_handler([]() {
    errs() << "new: " << strerror(errno) << '\n';

  PrettyStackTraceProgram X(argc, argv);

#ifdef _WIN32
  // Stack overflow
  AddVectoredExceptionHandler(0, handler);

  CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
  ClangTool Tool(OptionsParser.getCompilations(),
  return Tool.run(newFrontendActionFactory<MainAction>().get());
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151213/dc5668ee/attachment.html>

More information about the cfe-dev mailing list