LLVM命令行:如何重设参数? [英] LLVM CommandLine: how to reset arguments?

查看:484
本文介绍了LLVM命令行:如何重设参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个使用 LLVM命令行解析参数的静态库:

I have two static libs that use 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!
}

该应用程序与两个此lib链接,并且如果应用程序中只有1个lib,它们解析参数就很好,而如果同时具有两个libs,则它们在解析参数时会崩溃.

The app is linked against two this libs and they parse arguments just fine if having only 1 lib in the app and crash while parsing arguments if having both libs in the app.

似乎在与// arg一致的行中添加了一些全局静态参数列表(?),这使它们具有混合的参数列表并相互影响.

It seems that in lines with // arg argument is added in some global static list (?) of arguments and this makes them have mixed arguments list and affect to each other.

在声明参数之前,是否有机会重置该全局列表?

Is there any opportunity to reset that global list before declaring arguments?

PS.我发现CommandLine.cpp中的静态参数列表:

PS. I've found that static arguments list in CommandLine.cpp:

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

推荐答案

void main应该是什么? main返回int,并且在任何情况下库都不能提供main.如果这是在某个命名空间中,请仍然不要写void main.

What is void main supposed to be? main returns int, and in any case libraries can't provide a main. If this is in some namespace, still please don't write void main.

应该将全局列表作为一个功能,以便每个库都可以提供自己的(不同命名空间)参数.库应该本身在调用cl::ParseCommandLineOptions;只有真正的main函数才能做到这一点.此外,在库中将cl::opt用作局部变量没有意义,因为它仅在该函数的持续时间内存在. (如果您是应用程序,则可以安排在cl::opt到期之前调用cl::ParseCommandLineOptions.)

The global list is supposed to be a feature, so that each library can provide its own (differently-namespaced) arguments. The library should not be calling cl::ParseCommandLineOptions itself; only the true main function should do that. Additionally, in a library it doesn't make sense for cl::opt to be a local variable, because then it only exists for the duration of that function. (If you are the application, then you can arrange for cl::ParseCommandLineOptions to be called before the cl::opts expire).

这篇关于LLVM命令行:如何重设参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆