#include <gflags/gflags.h>DEFINE_bool(big_menu,true,"Include 'advanced' options in the menu listing");DEFINE_string(languages,"english,french,german","comma-separated list of languages to offer in the 'lang' menu");intmain(intargc,char**argv){google::ParseCommandLineFlags(&argc,&argv,true);cout<<"argc="<<argc<<endl;if(FLAGS_big_menu){cout<<"big menu is ture"<<endl;}else{cout<<"big menu is flase"<<endl;}cout<<"languages="<<FLAGS_languages<<endl;return0;}
运行程序
直接运行
run
1234
➜ bin ./sample
argc=1
big menu is ture
languages=english,french,german
help 命令
run
1234567891011121314151617181920212223
➜ bin ./sample --help
sample: Warning: SetUsageMessage() never called
Flags from /home/shougang/workspace/drive/Google/cmake_cpp_gflags/src/sample.cc:
-big_menu (Include 'advanced' options in the menu listing)type: bool
default: true -languages (comma-separated list of languages to offer in the 'lang' menu)type: string default: "english,french,german" Flags from src/gflags.cc:
-flagfile (load flags from file)type: string default: "" .........
➜ bin ./sample --helpshort
sample: Warning: SetUsageMessage() never called
Flags from /home/shougang/workspace/drive/Google/cmake_cpp_gflags/src/sample.cc:
-big_menu (Include 'advanced' options in the menu listing)type: bool
default: true -languages (comma-separated list of languages to offer in the 'lang' menu)type: string default: "english,french,german"
DEFINE_bool(big_menu,true,"Include 'advanced' options in the menu listing");DEFINE_string(languages,"english,french,german","comma-separated list of languages to offer in the 'lang' menu");