LLVM CommandLine: how to reset arguments?

I have two static libraries that use the LLVM command line to parse arguments:

// lib1 void main(int argc, const char **argv) { cl::opt<bool>LibOption1( ... ) // arg1 cl::ParseCommandLineOptions(argc, argv, "lib1\n"); } 

.

 // lib2 void main(int argc, const char **argv) { // need to reset arguments list here .. cl::opt<bool>LibOption2( ... ) // arg2 cl::ParseCommandLineOptions(argc, argv, "lib2\n"); // crash here! } 

The application is associated with these two libs, and they perfectly parse the arguments if there is only 1 lib in the application and the argument parsing fails if the application has both libraries.

It seems that in the lines with the // arg argument some global static list (?) Of arguments has been added, and this makes them mixed lists of arguments and affects each other.

Is there any way to reset for this global list before declaring the arguments?

PS. I found a list of static arguments in CommandLine.cpp :

 /// RegisteredOptionList - This is the list of the command line options that /// have statically constructed themselves. static Option *RegisteredOptionList = 0; 
0
source share
1 answer

What is void main ? main returns int , and in any case, libraries cannot provide the main one. If it is in some kind of namespace, please do not write void main .

The global list is assumed to be a function, so each library can provide its own (different names) arguments. The library should not itself call cl::ParseCommandLineOptions ; only the real core function should do it. In addition, it makes no sense in the library that cl::opt be a local variable, because then it exists only for the duration of this function. (If you are an application, you can make a call to cl::ParseCommandLineOptions before the expiration of cl::opt ).

+1
source

Source: https://habr.com/ru/post/1237624/


All Articles