cereal icon indicating copy to clipboard operation
cereal copied to clipboard

Put rapidjson under `cereal` namespace

Open oliora opened this issue 7 years ago • 6 comments

Before the last update of RapidJSON, it was placed under cereal::rapidjson namespace to avoid collisions with other versions of RapidJSON in the same binary, which was very handy. Unfortunately, it's not the case anymore, now Cereal's RapidJSON is defined under its default namespace rapidjson so it conflicts with other RapidJSONs. I propose to put cereal::rapidjson namespace back.

The fix is just to update three lines in include/cereal/external/rapidjson/rapidjson.h. I can send a PR if needed.

oliora avatar Nov 20 '18 18:11 oliora

You can provide a definition for CEREAL_RAPIDJSON_NAMESPACE_BEGIN in include/cereal/external/rapidjson/rapidjson.h to override the default behavior. That file has additional explanation on this as well.

AzothAmmo avatar Jan 02 '19 01:01 AzothAmmo

@AzothAmmo thank you! I did this already for myself but my point is that Cereal should be shipped with rapidjson under cereal namespace by default. The purpose of this is to avoid collision with target project’s rapidjson definitions, which is not a rare case since rapidjson is so widely used.

oliora avatar Jan 02 '19 09:01 oliora

IMHO it should not be shipped internally at all. This is what we have git-submodules, build systems and package managers for.

h-2 avatar Apr 30 '19 13:04 h-2

Please fix this "I include and mess up library x" issue, it is impossible to use both rapidjson and cereal in vcpkg since cereal has adds a lot of mods in rapidjson.

Laro88 avatar Sep 19 '19 06:09 Laro88

A library should not bundle/package other libraries, otherwise we can very easily get the diamond problem and ODR violations.

For example, on Ubuntu or Debian, if you install libcereal-dev rapidjson-dev and try to use them both, you will get compilation errors. See this sample code.

#include <cereal/archives/json.hpp>
#include <rapidjson/document.h>

int main() {}

The real solution is to use CMake's find_package(), and rely on cmake to find system's rapidjson.

Other solution is to define CEREAL_RAPIDJSON_NAMESPACE_BEGIN and the other two defines by default to put rapidjson under the namespace of cereal.

dimztimz avatar Dec 04 '19 14:12 dimztimz

If https://github.com/USCiLab/cereal/pull/604 addresses this would really appreciate it getting merged.

channingko-madden avatar May 16 '24 14:05 channingko-madden