参考http://dreamrunner.org/blog/2014/03/09/gflags-jian-ming-shi-yong/ 进行整理
写了一个小的测试程序,包含两部分内容,一部分是main.cc,另一部分是CMakeLists.txt
->main.cc
#include <iostream>
using std::cout;
using std::endl;
#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");
int main(int argc, char **argv) {
gflags::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;
return 0;
}
PROJECT(gflags)
SET(SRC main.cc)
INCLUDE_DIRECTORIES(library_path)
LINK_DIRECTORIES(lib_path)
ADD_EXECUTABLE(test ${SRC})
TARGET_LINK_LIBRARIES(test libgflags.a pthread)
结果:
①运行./test
②运行./test --big_menu=false
③运行./test --big_menu=false --languages=China