0
#include<string>
#include<iostream>
#include<json/json.h>
#include<cpr/cpr.h>

using namespace std;
using namespace cpr;


int main() {
    Response r = Get(Url{ "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd" });
    Json::Value data;
    Json::Reader reader;
    reader.parse(r.text, data);
    cout << data << endl;
}

I'm trying to get print out the response {"Bitcoin" {"USD: 23000"}}. When I just use response and cout r.text it runs perfectly. But when I use jsoncpp it says "There were build errors, would you like to run previous build?"

Build errors:

Build started... 1>------ Build started: Project: Project 1, Configuration: Debug x64 ------ 1>Main.obj : error LNK2019: unresolved external symbol "public: __cdecl Json::Value::Value(enum Json::ValueType)" (??0Value@Json@@QEAA@W4ValueType@1@@Z) referenced in function main 1>Main.obj : error LNK2019: unresolved external symbol "public: __cdecl Json::Value::~Value(void)" (??1Value@Json@@QEAA@XZ) referenced in function main 1>Main.obj : error LNK2019: unresolved external symbol "public: __cdecl Json::Reader::Reader(void)" (??0Reader@Json@@QEAA@XZ) referenced in function main 1>Main.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Json::Reader::parse(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class Json::Value &,bool)" (?parse@Reader@Json@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAVValue@2@_N@Z) referenced in function main 1>Main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits > & __cdecl Json::operator<<(class std::basic_ostream<char,struct std::char_traits > &,class Json::Value const &)" (??6Json@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV12@AEBVValue@0@@Z) referenced in function main

0

1 Answer 1

2

It appears that you treat JsonCPP as a header-only library, when it's enough to simply #include that header file.

However, looks like https://github.com/open-source-parsers/jsoncpp contains some source code, too. So you should probably build that library and link it.

Sign up to request clarification or add additional context in comments.

2 Comments

I used vcpkg to download jsoncpp and i linked it to visual studi already. if it wasnt linked then there would be a red line below the include would it not?
@JohnDoe - no, that red line would be there if the include file <json/json.h> is not found. It was found, so the code compiles OK. However, the library was either not listed as a link, or was not found.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.