- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用gFlags在 C++ 应用程序中,收集命令行标志:
DEFINE_string("output_dir", ".", "existing directory to dump output");
int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(argc, argv, true);
...
}
此标志有一个默认值,因此用户可以选择不在命令行上提供相同的值。 gFlags 中是否有任何 API 可以知道命令行中是否提供了该标志?我没有找到任何内容,因此使用以下 hack:
DEFINE_string("output_dir", ".", "existing directory to dump output");
static bool flag_set = false;
static void CheckFlags(const int argc, char** const argv) {
for (int i = 0; i < argc; i++) {
if (string(argv[i]).find("output_dir") != string::npos) {
flag_set = true;
break;
}
}
}
int main(int argc, char** argv) {
CheckFlags(argc, argv);
gflags::ParseCommandLineFlags(argc, argv, true);
if (flag_set) {
// blah.. blah..
}
return 0;
}
最佳答案
研究完gflags code详细来说,我发现了一个 API gflags::GetCommandLineFlagInfoOrDie(const char* name)
,它返回 CommandLineFlagInfo
,其中包含一个名为 is_default
的 bool 标志,其中如果在命令行中提供了该标志,则为 false:
struct CommandLineFlagInfo {
std::string name; // the name of the flag
//...
bool is_default; // true if the flag has the default value and
// has not been set explicitly from the cmdline
// or via SetCommandLineOption
//...
};
所以我不再需要黑客了:
DEFINE_string("output_dir", ".", "existing directory to dump output");
static bool flag_set = false;
int main(int argc, char** argv) {
CheckFlags(argc, argv);
gflags::ParseCommandLineFlags(argc, argv, true);
bool flag_not_set = gflags::GetCommandLineFlagInfoOrDie("output_dir").is_default;
if (!flag_not_set) {
// blah.. blah..
}
return 0;
}
关于c++ - 如何知道命令行中是否提供了 gflag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54295618/
我正在尝试构建包含 'gflags/gflags.h' 的库并且很难找到它。 我用自制软件安装了 gflags 和 glog。 CMake 输出说: -- Found installed versio
我正在Mac OS Mojave和Xcode 10上测试React Native 0.56.0-rc.2。 运行: react-native init TestProject --version="0
我正在开发 GAE django 非相关应用程序。我面临与 gflags 相关的错误。 NotImplementedError: The gflags library must be installe
我目前在尝试使用调试工具 GFlags 为所谓的“图像”删除标志“通过 DLL 启用堆标记”时出错:我正在调试的应用程序。 我收到“ 无法保存注册表错误 5 ”。但是,其他“启用堆...”标志没有问题
我使用gFlags在 C++ 应用程序中,收集命令行标志: DEFINE_string("output_dir", ".", "existing directory to dump output");
我正在尝试在由 Visual Studio 2013 构建的 Release x64 二进制文件上运行 gflags x64 以检测访问冲突。 我从 Microsoft 网站下载了 Windows 调
我在 selenium web 测试套件中使用 python gflags 模块时遇到问题。我基本上遵循 gflags github repo 中示例的方式。我通过 DEFINE_string 定义的
我正在尝试调试堆损坏问题。我看过有关 gflags 和应用程序验证程序的帖子。这两个工具之间有什么区别吗,或者应用程序验证器是围绕相同技术的漂亮 UI 吗? 最佳答案 Application veri
我目前正在尝试调试我的一个应用程序中的内存泄漏(是的,又是废话......),并尝试设置 gflags 设置,但对话框不会打开.我安装了 Windows 10 SDK(我在 Windows 7 x64
我在生产中有一个代码,自一周以来每天崩溃一次/两次。此崩溃是由于内存堆损坏 为了发现我的应用程序出了什么问题,我尝试使用 GFlags。 我已经使用 GFlags 激活了页面堆(我已经在 Window
我有一个应用程序会产生内存堆异常(损坏)。 在网上我发现了这样一句话: "GFlags.exe: A heap debug program. Using GFlags, you can establi
我这样使用 gflags: flags.DEFINE_string('logdir', None, 'Directory where logs are stor
我正在使用 gflags 来解析 C++ 应用程序(v140、x64)的命令行参数。出于某种原因,我在发布和 Debug模式下得到了不同的结果。在 Debug模式下,参数未被识别。 代码 #inclu
我正在尝试使用 GFlags 为小型应用程序启用页面堆,但由于某些原因它不起作用。 我写了一个小的 C++ 应用程序,它所做的只是破坏堆内存: int* a; a= (int*)malloc(1);
我安装了 gflags: $ ls /usr/local/lib/ | grep gflags libgflags.a libgflags_nothreads.a $ ls /usr/local/in
在尝试查找 Windows 应用程序中的一些内存泄漏时,我遇到了 gflags 的问题。 当我打开 ust 标志(为了收集内存分配堆栈跟踪)时,我的应用程序的内存增加速度比关闭该标志时快得多(它在 1
我刚刚开始使用 gflags对于我正在从事的几个 C++ 项目。我发现 --help 返回了大量标志,我目前正在使用 myapp --help | less 找到我正在寻找的标志。我很乐意为此完成制表
我做了以下程序: int main() { int* p = new int[10]; delete[] p; p[0] = 0; return 0; } 然后我在启用
我正在尝试让 oauth 在 Google App Engine (GAE) 上运行,但我无法导入 OAuth2Decorator , 因为它试图导入 gflags并失败了。 在命令行中我运行了 he
在一个生产站点上,我们的应用程序(*) 反复崩溃,但无法重现。分析崩溃转储清楚地表明它是堆损坏:崩溃发生在不同的位置,但始终在 kernel32!HeapFree/ntdll!RtlpLowFragH
我是一名优秀的程序员,十分优秀!