gflag使用


一、准备:

1.cmake 3.29.3 (低版本可能不支持2022)

Download CMake

2.vs 2022/2019

下载 Visual Studio Tools - 免费安装 Windows、Mac、Linux (microsoft.com)

3.glog源码

google/glog: C++ implementation of the Google logging module (github.com)

二、编译(和Glog类似)

1.cmake 找到源码路径

2.configure

3.generate 生成vs项目

4.打开项目 生成ALL_BUILD 和INSTALL

 

 

三、demo测试 需求编译好的gflas_static.lib 对应的头文件  并添加#pragma comment(lib, "shlwapi.lib")

#include <iostream>
#include <gflags/gflags.h>
#pragma comment(lib, "shlwapi.lib")
//DEFINE_string(变量名,默认值,描述);
DEFINE_string(name, "zhang san", "your name");
DEFINE_int32(age, 18, "your age");
int main(int argc, char** argv) {
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    std::cout << "your name is : " << FLAGS_name
        << ", your age is: " << FLAGS_name << std::endl;
    return 0;
}

 

不填添加shlwapi.lib 报错内容

 

 


posted @ 2024-06-28 15:47  BangZeng  阅读(4)  评论(0编辑  收藏  举报