# conflict with vtknlohmann and nlohmann

**URL:** https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977
**Category:** Development
**Created:** [December 8, 2024, 3:05am UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977 "2024-12-08T03:05:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![YeHuanjie](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yehuanjie/32/9579_2.png) [@YeHuanjie](https://discourse.vtk.org/u/YeHuanjie)
#### Post date: [December 8, 2024, 3:05am UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977/1 "2024-12-08T03:05:18Z")

</div>

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

```auto
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);

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 8, 2024, 6:09pm UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977/2 "2024-12-08T18:09:07Z")

</div>

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:

```cmake
VTK_MODULE_USE_EXTERNAL_VTK_nlohmannjson=ON

```

@jaswantp

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [December 9, 2024, 2:41am UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977/3 "2024-12-09T02:41:19Z")

</div>

> [@dgobbi](#):
>
> Apparently, the VTK 9.4.0 public API exposes VTK’s internal copy of nlohmannjson

@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.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [December 9, 2024, 2:03pm UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977/4 "2024-12-09T14:03:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 3, 2025, 10:21pm UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977/5 "2025-03-03T22:21:46Z")

</div>

FYI, there is progress in resolving this for 9.5. See [https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/11854](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11854) and [nlohmann::json and VTK's public API](https://discourse.vtk.org/t/nlohmann-json-and-vtks-public-api/15131)

---

<div class="post-metadata">

### Author: ![loganharbour](https://discourse.vtk.org/user_avatar/discourse.vtk.org/loganharbour/32/9932_2.png) [@loganharbour](https://discourse.vtk.org/u/loganharbour)
#### Post date: [April 22, 2025, 4:16pm UTC](https://discourse.vtk.org/t/conflict-with-vtknlohmann-and-nlohmann/14977/6 "2025-04-22T16:16:33Z")

</div>

For folks on v9.4.2, the following patch can be used as a hacky fix to incorporate the revert merge request linked above:

> <https://gist.github.com/loganharbour/e2c6707483b1f47bae57b5cce12ae6b0>
