pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
463 stars 133 forks source link

Unable to compile with preinstalled nlohmann json library #313

Closed elnoir closed 3 months ago

elnoir commented 3 months ago

My build environment is the folowing:

Reprosteps:

cd json_validator.git
mkdir build
cd build
cmake -S .. -B . -G "Visual Studio 16 2019" -Dnlohmann_json_DIR:PATH="../where/the/library/was/installed/nlohmann/share/cmake/nlohmann_json/"
cmake --build .

Result:

C:\work\git\json_validator.git\src\json-validator.cpp(878,1): error C2440: 'initializing': cannot convert from 'const nlohmann::json_abi_v3_11_2::json' to 'T' [C:\work\git\json_validator.git\build\nlohmann_json_schema_validator.vcxproj]
C:\work\git\json_validator.git\src\json-patch.cpp(68,14): error C3688: invalid literal suffix '_json'; literal operator or literal operator template 'operator ""_json' not found [C:\work\git\json_validator.git\build\nlohmann_json_schema_validator.vcxproj]

The first issue seems in incorrect casting: I beleive it should be

T value = instance.get<T>();

The second error seems to be regarding the move of the json literal:see here The following code did the trick.

using namespace nlohmann::literals;

After this modification the library compiles, but most of test cases are still broken due to the missing literals.

LecrisUT commented 3 months ago

What CMake version are you using? It should be handled by: https://github.com/pboettch/json-schema-validator/blob/08d8a52a8a1353b6bc953b63f7c6763e74e6047b/CMakeLists.txt#L88-L107

Normally if it doesn't find it automatically, it will still give you a version via FetchContent. Can you look into the build directory for _deps. If it's not there, or you see in the log that find_package succeeded, than there might be an issue with how nlohmann::json was packaged and installed?

PS: nlohmann_json_ROOT is preferred over nlohmann_json_DIR

elnoir commented 3 months ago

Okay, it seems it was an issue with the installation of the nlohmann json library. It was built from the develop branch instead of the version tag.

LecrisUT commented 3 months ago

Thanks, that's also useful to know that it will have to be addressed for the future version