网站首页 > 技术文章 正文
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;
}
猜你喜欢
- 2024-12-10 报错:java.lang.ClassNotFoundException:xxx
- 2024-12-10 Creo导出CAD配色文件
- 2024-12-10 Linux如何使用overlayfs堆叠多个目录?Overlayfs文件系统
- 2024-12-10 Win10又爆出蓝屏死机大Bug!教你如何修复它
- 2024-12-10 艾尔登法环玩不了怎么办 老头环打不开玩不了解决办法
- 2024-12-10 Python配置文件解析configparser
- 2024-12-10 如何解决库文件缺失问题?
- 2024-12-10 CentOS7开机自启动脚本(两种实现方式)
- 2024-12-10 python自动化测试框架之如何编写配置文件?使用ConfigParser试试
- 2024-12-10 Spring Boot 分离配置文件的 N 种方式
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- c语言min函数头文件 (77)
- asynccallback (87)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 无效的列索引 (74)