Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The cmake_import example does not build #1976

Closed
coderDec opened this issue Mar 9, 2020 · 5 comments
Closed

The cmake_import example does not build #1976

coderDec opened this issue Mar 9, 2020 · 5 comments
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@coderDec
Copy link

coderDec commented Mar 9, 2020

  • What is the issue you have?
    I am trying to build the cmake_import example json-develop/test/cmake_import/project.
    However it fails to build.
    Following error:

`
cmake .
-- The CXX compiler identification is GNU 7.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "Findnlohmann_json.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"nlohmann_json", but CMake did not find one.

Could not find a package configuration file provided by "nlohmann_json"
with any of the following names:

nlohmann_jsonConfig.cmake
nlohmann_json-config.cmake

Add the installation prefix of "nlohmann_json" to CMAKE_PREFIX_PATH or set
"nlohmann_json_DIR" to a directory containing one of the above files. If
"nlohmann_json" provides a separate development package or SDK, be sure it
has been installed.

-- Configuring incomplete, errors occurred!
`

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    I also put the nlohmann_jsonConfig.cmake file generated while building the project here.

  • What is the expected behavior?
    It should build the project

  • And what is the actual behavior instead?
    Unable to build using cmake.

  • Which compiler and operating system are you using? Is it a supported compiler?
    lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 18.04.3 LTS
    Release: 18.04
    Codename: bionic

  • Did you use a released version of the library or the version from the develop branch?
    develop branch

  • If you experience a compilation error: can you compile and run the unit tests?
    yes.

@t-b
Copy link
Contributor

t-b commented Mar 11, 2020

Can you post a MWE? We do have tests for the cmake import at https://github.com/nlohmann/json/tree/develop/test already.

@coderDec
Copy link
Author


#include </opt/nlohmann_json/json.hpp>
#include<string.h>
// for convenience
using json = nlohmann::json;

int
main(int argc, char *argv[])
{
// create an empty structure (null)
json j;

// add a number that is stored as double (note the implicit conversion of j to an object)
j["pi"] = 3.141;

// add a Boolean that is stored as bool
j["happy"] = true;

// add a string that is stored as std::string
j["name"] = "Niels";

// add another null object by passing nullptr
j["nothing"] = nullptr;

// add an object inside the object
j["answer"]["everything"] = 42;

// add an array that is stored as std::vector (using an initializer list)
j["list"] = { 1, 0, 2 };

// add another object (using an initializer list of pairs)
j["object"] = { {"currency", "USD"}, {"value", 42.99} };

return 0;
}

I have added the json.hpp file in single_include at /opt/nlohmann_json/json.hpp

Tried to compile it with the following command. It fails.
gcc -std=c++11 json_ade.cpp -o json_ade.o

@t-b
Copy link
Contributor

t-b commented Mar 12, 2020

@coderDec You have to pass the include path to gcc.

#include <nlohmann/json.hpp>
#include<string.h>
// for convenience
using json = nlohmann::json;

int
main(int argc, char *argv[])
{
// create an empty structure (null)
json j;

return 0;
}

with g++ -I single_include test.cpp from the base directory of this repository works here.

@nlohmann
Copy link
Owner

@coderDec Did #1976 (comment) solve your issue?

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Apr 11, 2020
@coderDec
Copy link
Author

Yes it did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants