Problem with Tooling system

Hello everyone,

I am currently using clang tooling for a tool on my own, and I recently started to develop it again.
I have a strange error while launching my binary

I got a lot of the followin

: CommandLine Error: Argument ‘version’ defined more than once!
: CommandLine Error: Argument ‘print-all-options’ defined more than once!
: CommandLine Error: Argument ‘print-options’ defined more than once!
: CommandLine Error: Argument ‘help-hidden’ defined more than once!
: CommandLine Error: Argument ‘help’ defined more than once!
: CommandLine Error: Argument ‘help-list-hidden’ defined more than once!
: CommandLine Error: Argument ‘help-list’ defined more than once!
: CommandLine Error: Argument ‘debug-only’ defined more than once!

So I tested back the example code from file:
~/llvm/tools/clang/include/clang/Tooling/CommonOptionsParser.h

Corrected for compilation errors:

#include <clang/Frontend/FrontendActions.h>
#include <clang/Tooling/Tooling.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <llvm/Support/CommandLine.h>

using namespace clang::tooling;
using namespace llvm;

static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
static cl::extrahelp MoreHelp("\nMore help text…");
int main(int argc, const char **argv) {
CommonOptionsParser OptionsParser(argc, argv);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactoryclang::SyntaxOnlyAction());
}

And the errors still occurs.

I searched a little where it could came from, but I didn’t find out.
I’ll continue to search, but any help is welcome

Thanks,

Hello everyone,

I am currently using clang tooling for a tool on my own, and I recently started to develop it again.
I have a strange error while launching my binary

I got a lot of the followin
<premain>: CommandLine Error: Argument 'version' defined more than once!
<premain>: CommandLine Error: Argument 'print-all-options' defined more than once!
<premain>: CommandLine Error: Argument 'print-options' defined more than once!
<premain>: CommandLine Error: Argument 'help-hidden' defined more than once!
<premain>: CommandLine Error: Argument 'help' defined more than once!
<premain>: CommandLine Error: Argument 'help-list-hidden' defined more than once!
<premain>: CommandLine Error: Argument 'help-list' defined more than once!
<premain>: CommandLine Error: Argument 'debug-only' defined more than once!

Hi Armand,

This almost certainly indicates that some static initializers of cl::opt<> are getting linked into your binary multiple times, and getting run repeatedly as a result.

I remember a similar problem existed even with the standard clang examples like PrintFunctionNames at some point.

Some details on your configuration will be useful: Is this a shared or static build? Is it a fresh LLVM checkout? Which platform?

Assuming you're using the CMake build system, can you try removing entries from target_link_libraries() and/or add_dependencies() in your tool's CMakeLists.txt and reporting back? Pretty sure that used to fix it.

If we can collect more data, it'd be nice to revisit and try to fix this properly.

Alp.

2013/11/22 Alp Toker <alp@nuanti.com>

clang.m4 (3.07 KB)