VTK json

Hello,

I am using VTK together with the Drogon C++ web framework.
Drogon depends on the system jsoncpp library, while VTK ships its own
vendored copy of jsoncpp under vtkjsoncpp (namespace vtkJson).

When both libraries are included in the same translation unit, I get
redefinition errors at compile time, for example:

In file included from /usr/local/include/drogon/plugins/SlashRemover.h:18,
                 from /usr/local/include/drogon/drogon.h:34,
                 from /home/site/merle/Projects/planet-sandbox/server/prototype_patients/patient_service/main.cc:3:
/usr/include/json/value.h:67:16: error: redefinition of 'class vtkJson::Exception'
   67 | class JSON_API Exception : public std::exception {
      |                ^~~~~~~~~
In file included from /usr/local/include/drogon/HttpRequest.h:24,
                 from /usr/local/include/drogon/HttpBinder.h:25,
                 from /usr/local/include/drogon/HttpAppFramework.h:23,
                 from /usr/local/include/drogon/drogon.h:23,
                 from /home/site/merle/Projects/planet-sandbox/server/prototype_patients/patient_service/main.cc:3:
/usr/local/vtk-9.5.2-native/include/vtk-9.6/vtkjsoncpp/json/json.h:610:16: note: previous definition of 'class vtkJson::Exception'
  610 | class JSON_API Exception : public std::exception {
      |                ^~~~~~~~~

In file included from /usr/local/include/drogon/plugins/SlashRemover.h:18,
                 from /usr/local/include/drogon/drogon.h:34,
                 from /home/site/merle/Projects/planet-sandbox/server/prototype_patients/patient_service/main.cc:3:
/usr/include/json/value.h:83:16: error: redefinition of 'class vtkJson::RuntimeError'
   83 | class JSON_API RuntimeError : public Exception {
      |                ^~~~~~~~~~~~
In file included from /usr/local/include/drogon/HttpRequest.h:24,
                 from /usr/local/include/drogon/HttpBinder.h:25,
                 from /usr/local/include/drogon/HttpAppFramework.h:23,
                 from /usr/local/include/drogon/drogon.h:23,
                 from /home/site/merle/Projects/planet-sandbox/server/prototype_patients/patient_service/main.cc:3:
/usr/local/vtk-9.5.2-native/include/vtk-9.6/vtkjsoncpp/json/json.h:629:16: note: previous definition of 'class vtkJson::RuntimeError'
  629 | class JSON_API RuntimeError : public Exception {

So I am wondering whether it would be better to rename the vtkJson namespace
directly instead of using a #define ?

That makes more difficult to update (as we’re bound to miss instances when updating).

Alas, we do use it publicly, so perhaps some way to not conflict is possible…but why not compile VTK to use the same jsoncpp rather than using its vendored copy instead?

Yes, you are right. I wasn’t sure whether using the system json would introduce others issues but building VTK with -DVTK_MODULE_USE_EXTERNAL_VTK_jsoncpp=YES solved my problem, and the project now compiles without conflicts.