网站首页 > 文章精选 正文
1、github 克隆 inih项目
git clone https://github.com/benhoyt/inih.git
2、开始构建,该项目是meson.build 构建
安装 meson,ninja
pip install meson
pip install ninja
3、编译构建,会在当前目录生成build
meson build
如下图:
4、加载动态库
1、需要将libinih.so,libINIReader.so 拷贝 /usr/lib64;
2、inih.pc,INIReader.pc 两个文件拷贝到如下目录
/usr/lib64/pkgconfig
/usr/share/pkgconfig
/usr/local/lib/pkgconfig
/usr/local/lib64/pkgconfig
3、执行命令ldconfig
4、检查是否配置成功
pkg-config --list-all
ldconfig -v | grep inih
ldconfig -v | grep INIReader
5、使用inih,INIReader
g++ 编译时添加 -lINIReader -linih
g++ -DWITH_TERARKDB -std=c++17 -o ./test-app1/main main.cpp -lINIReader -linih -lrocksdb -ldl -lzstd -lsnappy -llz4 -lbz2 -lz -u zenfs_filesystem_reg -lzbd
6、代码示例
配置文件
; Test config file for ini_example.c and INIReaderTest.cpp
[protocol] ; Protocol configuration
version=6 ; IPv6
[user]
name = Bob Smith ; Spaces around '=' are stripped
email = bob@smith.com ; And comments (like this) ignored
active = true ; Test a boolean
pi = 3.14159 ; Test a floating point number
trillion = 1000000000000 ; Test 64-bit integers
1、main.cpp 代码
不要忘记添加 #include "../cpp/INIReader.h"
// Example that shows simple usage of the INIReader class
#include <iostream>
#include "../cpp/INIReader.h"
int main()
{
INIReader reader("../examples/test.ini");
if (reader.ParseError() < 0) {
std::cout << "Can't load 'test.ini'\n";
return 1;
}
std::cout << "Config loaded from 'test.ini': version="
<< reader.GetInteger("protocol", "version", -1) << ", unsigned version="
<< reader.GetUnsigned("protocol", "version", -1) << ", trillion="
<< reader.GetInteger64("user", "trillion", -1) << ", unsigned trillion="
<< reader.GetUnsigned64("user", "trillion", -1) << ", name="
<< reader.Get("user", "name", "UNKNOWN") << ", email="
<< reader.Get("user", "email", "UNKNOWN") << ", pi="
<< reader.GetReal("user", "pi", -1) << ", active="
<< reader.GetBoolean("user", "active", true) << "\n";
std::cout << "Has values: user.name=" << reader.HasValue("user", "name")
<< ", user.nose=" << reader.HasValue("user", "nose") << "\n";
std::cout << "Has sections: user=" << reader.HasSection("user")
<< ", fizz=" << reader.HasSection("fizz") << "\n";
return 0;
}
猜你喜欢
- 2025-01-10 centos 7 升级OpenSSH
- 2025-01-10 Linux动态库和静态库教程
- 2025-01-10 Linux入门系列——软件包管理
- 2025-01-10 AI模型搭建-3
- 2025-01-10 AI模型搭建-2
- 2025-01-10 在深度Linux玩Windows游戏,可以这样安装wine的最新版
- 2025-01-10 ubuntu24.04 vscode调用 c++ opencv报错问题
- 2025-01-10 Nginx使用Lua-nginx模块脚本连接Redis数据库读取静态资源
- 2025-01-10 实用 | 一个高性能通信库的简单使用分享
- 2025-01-10 ffmpeg安装方式及配合python使用
- 04-23关于linux coreutils/sort.c源码的延展思考最小堆为什么不用自旋
- 04-23一文精通如何使用二叉树
- 04-23二叉树(Binary Tree)
- 04-23数据结构入门:树(Tree)详细介绍
- 04-23数据结构错题收录(六)
- 04-23Kubernetes原理深度解析:万字图文全总结!
- 04-23一站式速查知识总结,助您轻松驾驭容器编排技术(水平扩展控制)
- 04-23kubectl常用删除命令
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 计算机网络的拓扑结构是指() (45)
- 稳压管的稳压区是工作在什么区 (45)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)