1. 安装
执行命令
1
2
3
4
5
6
7
8
9
|
[root@VM-0-9-centos ~] # cd /home [root@VM-0-9-centos home] # mkdir jsoncpp [root@VM-0-9-centos home] # cd jsoncpp/ [root@VM-0-9-centos jsoncpp] # wget https://github.com/open-source-parsers/jsoncpp/archive/1.9.4.zip [root@VM-0-9-centos jsoncpp] # unzip 1.9.4.zip [root@VM-0-9-centos jsoncpp] # cd jsoncpp-1.9.4/ [root@VM-0-9-centos jsoncpp-1.9.4] # cmake . [root@VM-0-9-centos jsoncpp-1.9.4] # make [root@VM-0-9-centos jsoncpp-1.9.4] # make install |
2. 测试
创建测试文件夹和两个文件
1
2
3
4
|
[root@VM-0-9-centos jsoncpp-1.9.4] # mkdir xltest [root@VM-0-9-centos jsoncpp-1.9.4] # cd xltest [root@VM-0-9-centos xltest] # vim jsontest.json [root@VM-0-9-centos xltest] # vim jsontest.cpp |
其中jsontest.json 如下
1
|
[{ "name" : "Long" , "age" :6}] |
jsontest.cpp 如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <fstream> #include <iostream> #include <json/json.h> #include <cassert> #include <errno.h> #include <string.h> using namespace std; int main( void ) { ifstream ifs; ifs.open( "jsontest.json" ); assert (ifs.is_open()); Json::Reader reader; Json::Value root; if (!reader.parse(ifs, root, false )) { cout << "reader parse error: " << strerror ( errno ) << endl; return -1; } string name; int age; int size; size = root.size(); cout << "total " << size << " elements" << endl; for ( int i = 0; i < size; ++i) { name = root[i][ "name" ].asString(); age = root[i][ "age" ].asInt(); cout << "name: " << name << ", age: " << age << endl; } return 0; } |
编译
1
|
[root@VM-0-9-centos xltest] # g++ jsontest2.cpp |
执行可执行文件看到如下,安装成功
1
2
3
|
[root@VM-0-9-centos xltest] # ./a.out total 1 elements name: long, age: 6. |
执行可执行文件看到如下,安装成功
3. 问题及解决
问题如下,
[root@VM-0-9-centos xltest]# ./a.out
/a.out: error while loading shared libraries: libjsoncpp.so.24: cannot open shared object file: No such file or directory
**解决办法**
执行一下 ldconfig 就行了
1
|
[root@VM-0-9-centos xltest] # ldconfig |
若出现如下提示可直接忽略,不是错误。
ldconfig: /usr/local/lib64/libstdc++.so.6.0.28-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
到此这篇关于CentOS下Jsoncpp安装配置的方法的文章就介绍到这了,更多相关Jsoncpp安装配置内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/ShyLoneGirl/article/details/109576949