llvm - 如何在传递之间共享 cl::opt 参数?
问题描述
我在其中一个通行证中定义了一个 cl::opt 参数。
cl::opt<std::string> input("input", cl::init(""), cl::desc("the input file"), cl::value_desc("the input file"));
我想知道如何与另一个传递共享此参数?我试图将它移动到一个头文件并让另一个传递包含它,但它报告了一个多重定义错误。
解决方案
您需要将选项的存储设为外部。
在一些共享头文件中声明一个变量:
extern std::string input;
并仅在您的一个来源中定义它和选项本身:
std::string input;
cl::opt<std::string, true> inputFlag("input", cl::init(""), cl::desc("the input file"), cl::value_desc("the input file"), cl::location(input));
注意添加的cl::location(input)
参数,它指示cl::opt
将选项值存储在input
变量中。现在您可以input
从不同的 TU 访问 s 值,但仍然只有一个定义。
请参阅内部和外部存储部分。
推荐阅读
- python - 在 python [Windows] 中列出驱动器和网络位置
- java - 为特定的 Log4j2 记录器设置属性
- c# - 写入串行 COM 端口时如何实现异步功能?
- java - 并发 API LayoutLocalService.addLayout 在 LayoutSetLocalService 中抛出 StaleObjectStateException
- php - 无法在 PHP 中构建静态调用的类
- html - CSS - 如何将容器宽度调整为段落长度,防止它换行?
- java - Java 的 LingPipe 错误
- http - 将 http.NewServeMux 放入 http.NewServeMux
- php - 用于更改 SESSION 变量的脚本
- javascript - Angular 5将对象传递给组件