Giter Site home page Giter Site logo

Can't use nlohmann on Linux about json HOT 7 CLOSED

TomyFrank avatar TomyFrank commented on September 25, 2024
Can't use nlohmann on Linux

from json.

Comments (7)

nlohmann avatar nlohmann commented on September 25, 2024 1

Good that you managed it.

from json.

nlohmann avatar nlohmann commented on September 25, 2024

You need to properly configure the library search path to the json/include folder and then use #include <nlohmann/json.hpp>.

from json.

TomyFrank avatar TomyFrank commented on September 25, 2024

You have said it's a header-only library. so inclduing that would be enough useually but it's not.
How to properly configure the library search path to the json/include?

from json.

nlohmann avatar nlohmann commented on September 25, 2024

You did not use the single header version which is in the single_include folder. Otherwise, follow https://github.com/nlohmann/json?tab=readme-ov-file#integration.

from json.

TomyFrank avatar TomyFrank commented on September 25, 2024

The single_include folder doesn't exist in the repo folder so I downloaded both json and json_fwd headers in the project directory and changed the code:

#include <iostream>
#include "json.hpp"
#include "json_fwd.hpp"

  int main() {
      auto j = R"(
     {
      "happy": true,
      "pi": 3.141
     }
    )"_json;
    auto data = j.dump();
    std::cout << data << '\n';
    return 0;
}

Error:

 json.hpp:34:10: fatal error: nlohmann/adl_serializer.hpp: No such file or directory
   34 | #include <nlohmann/adl_serializer.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

from json.

nlohmann avatar nlohmann commented on September 25, 2024
  • You wrote that you cloned the repo, so there should be a single_include folder. Please check.
  • If you want to use the files in the include folder, then just including json.hpp or json_fwd.hpp (don't include both, you probably only need json.hpp), then you must set your include path.

from json.

TomyFrank avatar TomyFrank commented on September 25, 2024

Downloaded the ZIP and inslcued json.hpp and it runs. Thanks.
So the easiest way to use nlohmann-json is this way yeah?

from json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.