win10系统下 jsoncpp mingw 编译

本文介绍了如何在Windows 10系统中,使用Mingw和jsoncpp库进行编译。首先,需要安装Python 2.7+并添加到PATH,接着下载并安装Scons构建工具。然后,从github下载jsoncpp,根据说明配置编译选项,最终编译生成静态库,并给出简单的使用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jsoncpp是c++的一个json解析库

下载地址 https://github.com/open-source-parsers/jsoncpp


1、准备开发环境Python scons 

首先下载Python  2.7+,安装,并且加入到path 

然后下载  http://scons.org/pages/download.html

我下载的是 

官网解释(The Gzip tar file and Zip file are installable using the Python setup.py script in the package.

下载完成以后 进入 scans 目录

查看 redeme.txt

INSTALLATION
============

Assuming your system satisfies the installation requirements in the
previous section, install SCons from this package simply by running the
provided Python-standard setup script as follows:

        # python setup.py install

By default, the above command will do the following:

    --  Install the version-numbered "scons-2.4.1" and "sconsign-2.4.1"
        scripts in the default system script directory (/usr/bin or
        C:\Python*\Scripts, for example).  This can be disabled by
        specifying the "--no-version-script" option on the command
        line.

所以执行以下命令

F:\scons-2.4.1 python setup.py install


左右是会把 scons.py scons-2.4.1.py sconsign.py sconsign-2.4.1.py scons-time.py scons-time-2.4.1.py 等脚本 安装到 E:\java\Python27\Scripts  目录下

二、编译

查看jsoncpp的github介绍 。。。

Building and testing with SCons

Note: The SCons-based build system is deprecated. Please use CMake; see the section above.

JsonCpp can use Scons as a build system. Note that SCons requires Python to be installed.

Invoke SCons as follows:

scons platform=$PLATFORM [TARGET]
where $PLATFORM may be one of:

suncc: Sun C++ (Solaris)
vacpp: Visual Age C++ (AIX)
mingw
msvc6: Microsoft Visual Studio 6 service pack 5-6
msvc70: Microsoft Visual Studio 2002
msvc71: Microsoft Visual Studio 2003
msvc80: Microsoft Visual Studio 2005
msvc90: Microsoft Visual Studio 2008
linux-gcc: Gnu C++ (linux, also reported to work for Mac OS X)
If you are building with Microsoft Visual Studio 2008, you need to set up the environment by running vcvars32.bat (e.g. MSVC 2008 command prompt) before running SCons.

在jsoncpp的根目录执行如下命令进行编译

E:\git\jsoncpp>scons platform=mingw
然后会生成一个静态库
jsoncpp目录  --- buildscons\mingw\src\lib_json
这个目录下有四个文件

json_reader.o
json_value.o
json_writer.o
libjson_mingw_libmt.a
把整个目录全部拷贝到工程目录的跟目录下

然后按照如下步骤配置一下静态库



编译的时候会执行如下命令

g++ -DCURL_STATILIB -O3 -Wall -c -fmessage-length=0 -o "src\\main.o" "..\\src\\main.cpp" 
g++ "-LE:\\git\\jsoncpp\\buildscons\\mingw\\src\\lib_json" -o http-c.exe "src\\main.o" -ljson_mingw_libmt 

-ljson_mingw_libmt 是使用到的静态库。。。。

具体需要查一下g++的用法。。。。


然后简单写一个demo

std::string strValue = "{\"key1\":\"value1\",\"array\":[{\"key2\":\"value2\"},{\"key2\":\"value3\"},{\"key2\":\"value4\"}]}";

	Json::Reader reader;
	Json::Value value;

	if (reader.parse(strValue, value)) {
		std::string out = value["key1"].asString();
		std::cout << out << std::endl;
//		const Json::Value arrayObj = value["array"];
//		for (int i = 0; i < arrayObj.size(); i++) {
//			out = arrayObj[i]["key2"].asString();
//			std::cout << out;
//			if (i != arrayObj.size() – 1){
//				std::cout << std::endl;
//			}
//		}
	}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值