pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
466 stars 134 forks source link

Error undefined reference #257

Closed JosueGauthier closed 1 year ago

JosueGauthier commented 1 year ago

Hello,

I have some troubles in trying to use the lib. I have installed this according to the README but when I launch the Ctest i have 11 tests failed.

The following tests FAILED:
      7 - string-format-check-test (Failed)
     59 - JSON-Suite::Optional::Format::date-time (Failed)
     60 - JSON-Suite::Optional::Format::date (Failed)
     62 - JSON-Suite::Optional::Format::hostname (Failed)
     65 - JSON-Suite::Optional::Format::ipv4 (Failed)
     66 - JSON-Suite::Optional::Format::ipv6 (Failed)
     70 - JSON-Suite::Optional::Format::regex (Failed)
     72 - JSON-Suite::Optional::Format::time (Failed)
     75 - JSON-Suite::Optional::Format::uri (Failed)
     76 - JSON-Suite::Optional::Format::uuid (Failed)
     77 - Build::cmake-install (Failed)
Errors while running CTest

But I continued and I try to import it and run an example but i get the error : undefined reference to `nlohmann::json_schema::json_validator::json_validator(...)

So i compile it, it works, but when i try to link it get this error :

g++ -I/data/shared_libraries/nlohmann-3.11.2/include -I/data/shared_libraries/json-schema-validator-2.2.0/include /home/g/dev/test/json_schema/jsonschema.cpp -pthread -L/data/shared_libraries/json-schema-validator-2.2.0/lib -lnlohmann_json_schema_validator -o /home/g/dev/test/test/json_schema/jsonschema

/home/usr/bin/../libexec/gcc/x86_64-redhat-linux/11/ld: /tmp/ccnjrLR4.o: in function `main':
/home/g/dev/test/test/json_schema/jsonschema.cpp:32: undefined reference to `nlohmann::json_schema::json_validator::json_validator(nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const&, std::function<void (nlohmann::json_uri const&, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&)>, std::function<void (std::string const&, std::string const&)>, std::function<void (std::string const&, std::string const&, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const&)>)'
/home/root/usr/bin/../libexec/gcc/x86_64-redhat-linux/11/ld: /home/g/dev/test/test/json_schema/jsonschema.cpp:35: undefined reference to `nlohmann::json_schema::json_validator::validate(nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const&) const'
collect2: error: ld returned 1 exit status

So i checked via ld :

ld -L/data/shared_libraries/json-schema-validator-2.2.0/lib -lnlohmann_json_schema_validator /home/g/dev/test/test/json_schema/jsonschema.o -lpthread -o /home/g/dev/test/test/json_schema/jsonschema

ld: /home/g/dev/test/test/json_schema/jsonschema.o: undefined reference to symbol '__cxa_free_exception@@CXXABI_1.3'
//usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command line

I'm a little bit a lost and I found almost nothing on internet... Thanks

LecrisUT commented 1 year ago

Hard to tell what's the source of the error there. Try out different modes with nlohmann_json installed from your package manager, with it downloaded from FetchContent, with shared/static library. Make sure you have a clean build environment everytime, etc. If all else fails, try my PR #262, although it should not touch any of the logic over there, and record every system variable you have (g++/make/cmake/ninja versions etc.). If you can make it reprpoducible in a VM/docker, that would help us know what's going on there.

JosueGauthier commented 1 year ago

Hi, I ask to someone, and he solves this issue by making a simple make file and it works perfectly. Its seems there is a problem in the cmake but honestly I don't understand well the cmake files to tell you where he changes something. Thanks again,

LecrisUT commented 1 year ago

Note that you will have to maintain the makefile manually if you choose that approach. In #262 I have tried to fix most integration issues that newcomers will encounter and make it as straightforward as possible.

If you have any questions on how to configure/run a cmake project/library, do speak up because that will help us make the documentations as accessible as possible. We often forget what are the most fundamental steps that need to be documented as we take for granted much of the cmake basic after working with it for so long.