@nrailgun
        
        2015-09-14T10:33:10.000000Z
        字数 663
        阅读 3007
    gflags 解释命令行参数程序设计
apt-get install libgflags-dev
LIBS += lgflags
参数通过形如 DEFINE_type(var, default, prompt) 的宏定义。具体各个类型定义如下:
| 定义 | 数据类型 | 
|---|---|
DEFINE_string | 
 string | 
DEFINE_bool | 
 bool | 
DEFINE_int32 | 
 int32_t | 
DEFINE_int64 | 
 int64_t | 
DEFINE_uint64 | 
 uint64_t | 
DEFINE_double | 
 double | 
#include <stdio.h>#include <gflags/gflags.h>DEFINE_string(language, "English", "Whatever~~~");int main(int argc, char *argv[]){google::SetUsageMessage("You should not use this software!\n");google::ParseCommandLineFlags(&argc, &argv, true);if (FLAGS_language == "English") {google::ShowUsageWithFlags(argv[0]);}printf("%s\n", FLAGS_language.c_str());return 0;}
方式和普通程序没有差别:
procname --language='Chinese'
或者:
procname -language 'Chinese'
