目录
  • 1.安装
  • 2.测试
  • 3.问题及解决

1. 安装

执行命令

[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. 测试

创建测试文件夹和两个文件

[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 如下

[{"name":"Long", "age":6}]

jsontest.cpp 如下

#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;
}

编译

[root@VM-0-9-centos xltest]# g++ jsontest2.cpp

执行可执行文件看到如下,安装成功

[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 就行了

[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安装配置内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。