ozindfw
ozindfw

Reputation: 21

basic trouble making the nlohmann json library work in Visual Studio 19

I'm a neophyte. I know I'm doing something bonheaded. I've search this and other fora for the last day and I'm stuck. I'm trying to use nlohmann's json library. I'm getting over 200 error messages, most of which seem to be rooted in the fact that the compiler can't see the header references in the main json.hpp file, but can see the json.hpp file.

I've copied the nlohmann library contents into the source folder and this is the code at the moment:

#include <iostream>
#include "nlohmann\json.hpp"
using json = nlohmann::json;

int main()
{
    std::cout << "Hello World!\n";
}

I'm trying to minimize the number of variables I have to chase.

VS is finding the json.hpp file (no squiggly underline once I finally spelled it right, and a bunch of stuff in solution explorer under json.hpp and nlohmann) It also seems to be seeing the subdirectories of nlohmann

the 'json' after nlohmann:: has a squiggly underline; the popup says: namespace 'nlohmann' has no member 'json'

the first 20 or so 211 (!) error messages are code E1696 'cannot open source file' pointing to apparent references from json.hpp an example is: "E1696 cannot open source file "nlohmann/adl_serializer.hpp" json5 C:\Users\Rich\source\repos\json5\json5\nlohmann\json.hpp"

I've added the 'nlohmann' directory to the include directories that the compiler looks for (Project|properties|C/C++|Additional Include Directories) - no change in error message count. Do I need to manually add all of the subdirectories?

Upvotes: 0

Views: 2790

Answers (1)

Mostafa Garana
Mostafa Garana

Reputation: 51

I Think you maybe using an older version of c++ (older than c++11). Try adding this flag to the command -std=c++11.

Upvotes: 2

Related Questions