在模块化程序中使用Boost.Program_options

发布于 2024-09-13 22:19:58 字数 267 浏览 2 评论 0原文

我使用的代码由一组模块组成,编译为单独的库。 反过来,库以不同的组合链接以构建不同的二进制文件。

所以,这是非常普通的。

不同的模块使用不同的命令行参数,我想使用 Boost.Program_options 进行解析。

由于命令行参数集取决于链接在一起的库,因此我事先不知道所有参数,因此无法将它们添加到 program_options::options_description 中。

如何让每个模块添加其命令行参数并稍后读取它们?

谢谢

The code I use consists of set of modules, compiled to individual libraries.
Libraries in turn, are linked in different combinations to build different binaries.

So for, it's pretty ordinal.

Different modules use different command line arguments and I want to use Boost.Program_options for parsing.

Since the set of command line arguments depends on what libraries are link together, I don't know in advance all arguments and therefore can not add them to program_options::options_description.

How do you enable to each module to add it's command line arguments and later read them?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-09-20 22:19:58

例如,通过使用 options_description 的成员函数 add(const options_description & desc) 将模块中的选项收集到一个描述中:

选项描述&添加(const options_description & desc) ;
添加一组选项说明。这与在 desc 中单独添加所有 option_descriptions 的效果相同,只是输出运算符将显示单独的组。返回*this

提取选项可以简单地通过将 variables_map 传递给模块来完成。

E.g. by using options_descriptions member function add(const options_description & desc) to collect the options from your modules together in one description:

options_description & add(const options_description & desc) ;
Adds a group of option description. This has the same effect as adding all option_descriptions in desc individually, except that output operator will show a separate group. Returns *this.

Extracting options could be simply done by passing e.g. the variables_map around to the modules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文