PointCloudLibrary / PointCloudLibrary/pcl

[3rd Party] VTK 9.4 exposes nlohmann::json publicly, causing ODR conflicts

Open
#6,360 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

kind: bug
Dominant language
C++
Stars
11.1k
Forks
4.7k
Avg merge
4d 10h
Merged PRs (30d)
6

Description

Describe the bug

When using PCL linked with VTK 9.4, the internal nlohmann::json bundled inside VTK (renamed to vtknlohmann in vtk_nlohmannjson.h) is exposed publicly. This causes conflicts when a project also uses a separate nlohmann::json configuration: the compiler raises One Definition Rule (ODR) conflicts for any functions that use the project’s own nlohmann::json. Moreover, the compiler does not understand the nlohmann::json and kind of forces me to use vtknlohmann::json, which is the internal VTK json.

Context

I was trying to add PCL to my project for point cloud visualization and encountered this bug. PCL installation itself works flawlessly (except for a warning “PATH is too long to be changed,” which I resolved manually).

I am on Windows 11 using Visual Studio 2022.

To Reproduce

  1. Install, configure, and link nlohmann::json for your project using CMake (I used FetchContent).
  2. Install PCL (latest release) and configure CMake to link it to your project.
  3. Write a function using your own nlohmann::json.
  4. Write a function that uses VTK (the error appeared when I tried to visualize a point cloud).

Screenshots / Code snippets

Screenshot showing the conflict:

Image

Code snippet indicated by the last error:

Image

Note the error at line 62: the compiler expects vtknlohmann instead of nlohmann because VTK redefines it here:

Image

My Environment

  • OS: Windows 11 24H2
  • Compiler: MSVC 19.44.35217.0
  • PCL Version: 1.15.1

Possible Solutions

Here are some resources about this problem:

This problem appears to be resolved in VTK 9.5. Possible approaches:

  • Upgrade the VTK version distributed with PCL to 9.5.
  • Rebuild VTK with VTK_MODULE_USE_EXTERNAL_VTK_nlohmannjson=ON.
  • Apply a workaround in PCL to avoid conflicts while keeping VTK 9.4.

Additional Information

This is my first issue submission ever, so sorry if it’s not perfect.

I tried exploring the source code to propose a fix, but haven’t made progress yet. I plan to investigate further.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the VTK 9.4 handling described in vtk_nlohmannjson.h and the linked VTK discussions and merge requests. Reproduce the PCL 1.15.1 integration with an external nlohmann::json configuration, then determine whether the VTK upgrade, external VTK dependency, or a PCL workaround removes the public vtknlohmann conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.