gflags 下载,编译,安装,使用
gflags下载,安装,使用
下载地址:
官方主页:https://github.com/gflags/gflags
当前最新下载地址
wget https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz
tar xvf v2.2.2.tar.gz
cd gflags-2.2.2/
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON -DCMAKE_INSTALL_PREFIX=$(pwd)/../../install ..
不指定安装目录,就直接安装到系统里面了。
示例代码
#include "bits/stdc++.h"
using namespace std;
#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[])
{
google::SetVersionString("V1.0.0@const.net.cn");
google::SetUsageMessage("-help ");
google::ParseCommandLineFlags(&argc, &argv, true);
std::cout << FLAGS_big_menu << std::endl;
std::cout << FLAGS_languages << std::endl;
return 0;
}
g++ test_gflags.cpp -o test_gflags -I ./install/include -L ./install/lib -lgflags
运行
./test_gflags -version
test_gflags version V1.0.0@const.net.cn
./test_gflags -helpshort
test_gflags: -help
Flags from test_gflags.cpp:
-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"
./test_gflags -big_menu=false
0
english,french,german
./test_gflags -big_menu=true
1
english,french,german
./test_gflags -big_menu=true -languages=zh-cn
1
zh-cn
本文链接地址:https://const.net.cn/558.html