欢迎光临
我们一直在努力

CentOS下怎么安装配置Jsoncpp

今天小编给大家分享一下CentOS下怎么安装配置Jsoncpp的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

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”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注云搜网行业资讯频道。

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。