【发布时间】:2018-02-05 13:54:37
【问题描述】:
我是 json 新手,我试图从本教程站点读取我的 json 文件 https://en.wikibooks.org/wiki/JsonCpp
但是我得到一些链接器错误
1>----- 构建开始:项目:TwilightAdventure,配置:调试 Win32 ------ 1> 创建库 C:\Users\MinTeckNG\Desktop\TwilightAdventure\Debug\TwilightAdventure.lib 和对象 C:\Users\MinTeckNG\Desktop\TwilightAdventure\Debug\TwilightAdventure.exp 1>LoadingMap.obj:错误LNK2019:无法解析的外部符号“public:__thiscall Json::Reader::Reader(void)”(??0Reader@Json@@QAE@XZ) 在函数“public:void __thiscall LoadingMap::”中引用ReadJsonFileTest(void)" (?ReadJsonFileTest@LoadingMap@@QAEXXZ) 1>C:\Users\MinTeckNG\Desktop\TwilightAdventure\Debug\TwilightAdventure.exe : 致命错误 LNK1120: 1 unresolved externals ========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
error picture lnk2019 未解析的外部符号
{
"actors": [
{
"name": "Ground",
"pos": {
"x": 2592.0,
"y": 96.0
}
},
{
"name": "Grass",
"pos": {
"x": 2656.0,
"y": 96.0
}
}
}
我的代码
#include "LoadingMap.h"
#include <fstream>
LoadingMap::LoadingMap(void)
{
}
LoadingMap::~LoadingMap(void)
{
}
/*const char *LoadingMap::GetFileName(int stage, int difficulties)
{
char a = '0';
const char *ptr = &a;
return ptr;
}*/
/*void LoadingMap::ReadJsonFile(const char *filename)
{
}*/
void LoadingMap::ReadJsonFileTest()
{
std::ifstream ifs("1-1-0.json");
Json::Reader reader;
//Json::Value obj;
//reader.parse(ifs, obj);
//std::cout << "Object type: " << obj["name"].asString() << std::endl;
//const Json::Value& pos = obj["pos"];
//std::cout << " x: " << pos[0]["x"].asUInt();
//std::cout << " y: " << pos[1]["y"].asUInt();
}
我的头文件
#pragma once
#include <iostream>
#include <fstream>
#include <json/json.h>
class LoadingMap
{
public:
LoadingMap(void);
~LoadingMap(void);
//const char *GetFileName(int stage, int difficulties);
//void ReadJsonFile(const char *filename);
void ReadJsonFileTest();
private:
};
好吧,代码基本上什么都没有,还没有实现,我尝试按照教程进行修改。
【问题讨论】:
-
请发布链接器错误,删除不需要的 cmets 并发布整个 LoadingMap 代码
-
从“输出”选项卡复制错误消息的文本。它的格式应该可以很容易地复制和粘贴到您的问题中。
-
错误图片链接,显示我的visual studio错误
-
很简单:你还没有链接到你的依赖Json::Reader。