CentOS下Jsoncpp安裝配置的方法
1. 安裝
執(zhí)行命令
[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. 測試
創(chuàng)建測試文件夾和兩個文件
[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
執(zhí)行可執(zhí)行文件看到如下,安裝成功
[root@VM-0-9-centos xltest]# ./a.out total 1 elements name: long, age: 6.
執(zhí)行可執(zhí)行文件看到如下,安裝成功
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
**解決辦法**
執(zhí)行一下 ldconfig 就行了
[root@VM-0-9-centos xltest]# ldconfig
若出現(xiàn)如下提示可直接忽略,不是錯誤。
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.
到此這篇關(guān)于CentOS下Jsoncpp安裝配置的方法的文章就介紹到這了,更多相關(guān)Jsoncpp安裝配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何在C++中通過模板去除強(qiáng)制轉(zhuǎn)換
本文講解的是如何在C++中通過模板去除強(qiáng)制轉(zhuǎn)換,在編程工作中應(yīng)盡量少使用強(qiáng)制類型轉(zhuǎn)換,模板有助于我們實現(xiàn)這一目的,需要的朋友可以參考下2015-07-07
如何使用visual studio2019創(chuàng)建簡單的MFC窗口(使用C++)
這篇文章主要介紹了如何使用visual studio2019創(chuàng)建簡單的MFC窗口(使用C++),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
C++使用map實現(xiàn)多進(jìn)程拷貝文件的程序思路
這篇文章主要介紹了C++使用mmap實現(xiàn)多進(jìn)程拷貝文件,通過本文給大家分享程序思路及完整代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-12-12
C語言程序設(shè)計譚浩強(qiáng)第五版課后答案(第三章習(xí)題答案)
這篇文章主要介紹了C語言程序設(shè)計譚浩強(qiáng)第五版課后答案(第三章習(xí)題答案),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2021-04-04

