美文网首页
[配置] VS2005_C++_JsonCpp

[配置] VS2005_C++_JsonCpp

作者: CrazyTiger | 来源:发表于2018-03-14 17:58 被阅读0次

    1.参考资料

    jsoncpp在linux和windows下的编译及使用详解

    2.下载源码

    jsoncpp的下载地址

    3.编译源码

    3.1选择解决方案

    jsoncpp-master\makefiles\ 目录下有两个工程
    msvc2010: Format Version 11.00,VS2010版本。
    vs71: Format Version 8.00,不知道是哪个VS版本。
    宿主程序的解决方案是VS2005的,Format Version = 9.0。VS2005可以打开9.0和9.0版本以下的解决方案,但是不能打开高于9.0的解决方案。因此,只能选择vs71项目。
    如果宿主程序是VC6开发的,那么就麻烦了,那要怎么弄,还不知道,先不管了。

    用VS2005打开,根据提示,进行项目转化,转化结束后会成功

    3.2RuntimeLibrary

    宿主项目和lib_json项目都要使用一致的配置。

    1. Debug:Multi-threaded Debug DLL (/MDd)
    2. Release:Multi-threaded DLL(/MD)

    3.3编译lib_json,会遇到几个错误。

    错误1

    "stdint.h": No such file or directory”
    

    将 config.h中的#include<stdint.h>注释掉,手动添加typedef int64t, uint64t,如下:

    // @ file: config.h
    //#include <stdint.h> //typedef int64_t, uint64_t
    typedef long long int64_t;
    typedef unsigned long long uint64_t;
    

    "stdint.h" 是C99标准的库,而VS2005没有,但是根据config.h使用此头文件的目的是typedef int64t, uint64t,所以我们只需手动实现它即可成功编译连接,应该不会再报这个错误。

    错误2

    gathermac.cpp
    Compiling resources...
    Linking...
    Generating code
    c:\resource\vccode\qiyi\jsoncpp-src-0.5.0\jsoncpp-src-0.5.0\src\lib_json\json_reader.cpp : fatal error C1083: Cannot open compiler generated file: '../../build/vs71/release/lib_json\json_reader.asm': No such file or directory
    LINK : fatal error LNK1257: code generation failed
    Build log was saved at "file://c:\resource\vccode\qiyi\gathermac\gathermac\Release\BuildLog.htm"
    gathermac - 2 error(s), 0 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
    

    修改项目属性: C/C++ -> Output Files -> Assembler Output 修改为** No Listing**。

    4.宿主程序

    1.在D:\JSON\目录下,创建一个MFC项目: JsonCppTest
    D:\JSON\JsonCppTest\

    2.在JsonCppTest项目中,创建include目录和lib目录
    D:\JSON\JsonCppTest\include
    D:\JSON\JsonCppTest\lib\

    3.拷贝include目录
    把Json文件夹(路径:D:\JsonCpp\jsoncpp-master\include\Json),
    拷贝到D:\JSON\JsonCppTest\include\下面

    4.拷贝lib文件
    拷贝下面两个lib目录下:lib目录:D:\JSON\JsonCppTest\lib
    D:\JsonCpp\jsoncpp-master\build\vs71\debug\lib_json\json_vc71_libmtd.lib
    D:\JsonCpp\jsoncpp-master\build\vs71\release\lib_json\json_vc71_libmt.lib

    5.配置include目录
    属性 -> 配置属性 -> C/C++ -> Additional Include Directories
    配置为 D:\JSON\JsonCppTest\include\

    6.配置lib目录
    属性 -> 配置属性 -> Linker -> General -> Additional Library Directories
    配置为 D:\JSON\JsonCppTest\lib\

    7.配置lib文件
    属性 -> 配置属性 -> Linker -> Input -> Additional Dependencies
    Debug配置为 json_vc71_libmtd.lib
    Release配置为 json_vc71_libmt.lib

    5.宿主程序Warning LNK4009

    参考文章 warning LNK4099: PDB 原因及解决方案

    简单的说(我的解决方法)

    1. 查看项目配置:Configuration Properties -> C/C++ -> Output Files -> Program Database File Name: $(IntDir)\vc80.pdb
    2. JsonCppTest和lib_json,宿主项目和lib_json项目都是设置为vc80.pdb,自然就冲突了。分别改为JsonCppTest.pdb和lib_json.pdb就好了。

    6.编码

    参考文章 C++ 解析Json——jsoncpp

    相关文章

      网友评论

          本文标题:[配置] VS2005_C++_JsonCpp

          本文链接:https://www.haomeiwen.com/subject/erzfqftx.html