conflict with vtknlohmann and nlohmann

when i use pcl(1.14.0) and nlohmann(3.10.0) in my project, vtk(9.4.0) reports make error. it seems that there is a conflict with vtknlohmann and nlohmann. How can i use nlohmann in my project

In file included from /usr/local/include/vtk-9.4/vtkAbstractArray.h:61,
                 from /usr/local/include/vtk-9.4/vtkDataArray.h:26,
                 from /usr/local/include/vtk-9.4/vtkPoints.h:18,
                 from /usr/local/include/pcl-1.14/pcl/visualization/point_cloud_geometry_handlers.h:50,
                 from /usr/local/include/pcl-1.14/pcl/visualization/common/actor_map.h:40,
                 from /usr/local/include/pcl-1.14/pcl/visualization/pcl_visualizer.h:48,
                 from /home/tplink/factory_simulation/test_pcl/src/utils.h:14,
                 from /home/tplink/factory_simulation/test_pcl/src/batch_test_tless.cc:10:
/usr/local/include/vtk-9.4/vtkAbstractArray.h:82:3: error: ‘vtknlohmann’ does not name a type; did you mean ‘nlohmann’?
   82 |   nlohmann::json SerializeValues();
      |   ^~~~~~~~
/home/tplink/factory_simulation/test_pcl/src/read_json.h:6:48: error: ‘vtknlohmann’ has not been declared
    6 | int ReadSceneCameraJson(std::string file_path, nlohmann::json& j);
      |                                                ^~~~~~~~
/home/tplink/factory_simulation/test_pcl/src/read_json.h:8:44: error: ‘vtknlohmann’ has not been declared
    8 | int ReadSceneGTJson(std::string file_path, nlohmann::json& j);
      |                                            ^~~~~~~~
/home/tplink/factory_simulation/test_pcl/src/read_json.h:10:48: error: ‘vtknlohmann’ has not been declared
   10 | int ReadSceneGTInfoJson(std::string file_path, nlohmann::json& j);
      |                                                ^~~~~~~~
/home/tplink/factory_simulation/test_pcl/src/batch_test_tless.cc: In function ‘int BatchTestTLESS()’:
/home/tplink/factory_simulation/test_pcl/src/batch_test_tless.cc:62:2: error: ‘vtknlohmann’ has not been declared
   62 |  nlohmann::json scene_camera_json;
      |  ^~~~~~~~
/home/tplink/factory_simulation/test_pcl/src/batch_test_tless.cc:63:70: error: ‘scene_camera_json’ was not declared in this scope
   63 |  ReadSceneCameraJson("./model/tless_batch/000000/scene_camera.json", scene_camera_json);

Apparently, the VTK 9.4.0 public API exposes VTK’s internal copy of nlohmannjson (this wasn’t the case in VTK 9.3.1). If you built and installed VTK yourself, then you can reconfigure VTK to use the same nlohmannjson that you use in your app, and then re-install VTK. This should remove the conflict.

Try changing the following setting in VTK’s cmake cache, and then rebuild:

VTK_MODULE_USE_EXTERNAL_VTK_nlohmannjson=ON

@jaswantp

@jcfr Is this going to be a problem for 3D Slicer and other applications, too?

@jaswantp Was this really needed? VTK generally uses third-party libraries internally and does not expose any symbols from them on the public API.

It could have been avoided. vtkAbstractArray would have to return a stringified json and the vtkCellGridWriter would have to parse the json from that string.

I can see this as a big issue for applications adopting VTK 9.4

@cory.quammen @mwestphal