Issues including jsonCpp headers

I am trying to implement jsoncpp libraries in my C ++ code, I wrote a simple piece of code to try it, and it does not even compile.

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>

#ifndef json_included
#define json_included
#include "jsoncpp\include\json\json.h"
#endif

//#include "json\jsonC\json.h"
int main(int argc, char **argv)
{

std::string example = "{\"array\":[\"item1\", \"item2\"], \"not an array\":\"asdf\"}";
Json::Value value;
Json::Reader reader;

bool parsed = reader.parse(example, value, false);
std::cout << parsed;
return 0;
}

The errors I get are the following:

undefined reference to `Json::Reader::parse(std::string const&, Json::Value&, bool)'
undefined reference to `Json::Reader::Reader()'
undefined reference to `Json::Value::~Value()'
undefined reference to `Json::Value::Value(Json::ValueType)'

I'm a little new to C ++, is there something that I am missing from the include statement? Or does jsonCpp need something extra?

Thank you for your time!

+3
source share
6 answers

Your code compiles, but it is not related. You forgot to provide shared JSON library files for your linker (or in newer versions to add jsoncpp.cpp merged into your project).

Without knowing more about your development environment, it is difficult for you to give more specific instructions.

, ++; ++, cstdio, stdio.h, . ++ string , "" - JSON, .

+5

"Undefined " . jsoncpp , , .so,.a,.lib .dll?

jsoncpp README, scons. , , .so,.a,.lib .dll. (, " " IDE).

+2

( CodeBlocks IDE Ubuntu) , json.cpp( python amalgamate.py jsoncpp) .

, -c jsoncpp.cpp g++.

+1

json-, . -ljson_linux-gcc-4.4.3_libmt

, , ./USR/

Visual Studio, .lib Project Properties, Linker, Input, Additional Dependencies Project, Linker, General, Additional Library Directories

0

:

  • jsoncpp , amalgated .

  • , #include

0

After compiling jsoncpp, you can find the libraries in the libs / folder. For convenience, you can put it in / usr / lib and then bind it at run time by passing -llibjson_linux-gcc-4.4.3_libmt as an argument to g ++.

I renamed libjson_linux-gcc-4.4.3_libmt.so to libjson.so and can link it with -ljson.

0
source

Source: https://habr.com/ru/post/1795877/


All Articles