VTK-9.3 VTK.sln build failed

I wanted to build VTK.sln but I got the following errors:

How can I fix them?

@jfausty @mwestphal These are duplicate symbol errors from the implicit array templates and vtkToImplicitRamerDouglasPeuckerStrategy - I feel like we’ve seen this before and dealt with it, but I’m not finding a reference - does this ring a bell with you?

I built from the master two days ago and it was ok.

1 Like

Hello,

From c++ - error LNK2005, already defined? - Stack Overflow :

In the Project’s Settings, add /FORCE:MULTIPLE to the Linker’s Command Line options.

From MSDN: “Use /FORCE:MULTIPLE to create an output file whether or not LINK finds more than one definition for a symbol.”

Though, this is considered dirty. It’s likely a guard, anonymous namespace or extern is missing in VTK sources.

take care,

PC

Does this occur with 9.3 RC2 ? I built that version yesterday on Visual Studio 2022 (17.8 preview 6), and didn’t see this problem. With which VS version did it happen?

Edit: I can reproduce the error with VS 2019 (16.11.30).

Correction: I see it happen on VS 2022 too; I probably just missed it before since we don’t need the FiltersReduction module.

Does this happen with the Ninja generator? We don’t test the VS generator that well for VTK.

I don´t see any issues with the Ninja or VS generator. I built from the master yesterday.

I built the VTK 9.3.0 release just now and still see this error. CMake 3.27.7 with “Visual Studio 17 2022” generator, VS 2022 17.7.6 on Windows 10 22H2; these are the options I manually set via CMake GUI:

-DVTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2:STRING="YES"
-DVTK_MODULE_ENABLE_VTK_ViewsQt:STRING="YES"
-DVTK_MODULE_ENABLE_VTK_GUISupportQt:STRING="YES"
-DVTK_MODULE_ENABLE_VTK_RenderingQt:STRING="YES"
-DQt6_DIR:PATH="PATH_TO_QT/6.6.0/msvc2019_64/lib/cmake/Qt6"
-DVTK_MODULE_ENABLE_VTK_RenderingOpenXR:STRING="YES"
-DOpenXR_INCLUDE_DIR:PATH="PATH_TO_OPENXR/include/openxr"
-DOpenXR_LIBRARY:FILEPATH="PATH_TO_OPENXR/x64/lib/openxr_loader.lib" 
-DVTK_MODULE_ENABLE_VTK_RenderingOpenVR:STRING="YES"
-DOpenVR_LIBRARY:FILEPATH="PATH_TO_OPENVR/lib/win64/openvr_api.lib" 
-DOpenVR_INCLUDE_DIR:PATH="PATH_TO_OPENVR/headers"

(I haven’t tested whether any of these are strictly required for the error to happen, they are just the ones that I need to set up VTK for my needs).

EDIT: The errors only appear to happen when building Debug configuration.

EDIT2: git master builds fine.

Thanks; hopefully we can just find some commits that need backporting then.

Also, you can try building with VS’ nmake instead of a VS solution. The CMake generator for this is called “NMake Makefiles”: cmake -g "NMake Makefiles" -DCMAKE_PREFIX_PATH=... ...

best,

PC

EDIT: make sure to run the proper VS’ vcvarsall.bat before compiling.

I have the same link errors concerning vtkFiltersReduction when building version 9.3.0, using CMake 3.27.9 and VS2022 17.8.2. I’m building using the generated VTK.sln. The problem only occurred for me in Debug configuration, not Release configuration.

I got the same link error.

The issue can be resolved by the following:

  • Locate file: \src\Common\Core\vtkConstantImplicitBackend.h
  • Replace "struct VTKCOMMONCORE_EXPORT vtkConstantImplicitBackend final " with “struct vtkConstantImplicitBackend final”. Basically, it is to remove “VTKCOMMONCORE_EXPORT”
  • Build again and the issue will disappear.

Hope this could help.

3 Likes

Just for reference - see also the vtk issue tracker, issue #19166 where this fix is also mentioned.

I had the same linking error while building VTK today. (Visual Studio Professional 2022 (64-bit) - Version 17.6.2)

181>vtkCommonCore-9.3d.lib(vtkCommonCore-9.3d.dll) : error LNK2005: "public: __cdecl vtkConstantImplicitBackend<float>::vtkConstantImplicitBackend<float>(float)" (??0?$vtkConstantImplicitBackend@M@@QEAA@M@Z) already defined in vtkToImplicitRamerDouglasPeuckerStrategy.obj
181>vtkCommonCore-9.3d.lib(vtkCommonCore-9.3d.dll) : error LNK2005: "public: __cdecl vtkConstantImplicitBackend<double>::vtkConstantImplicitBackend<double>(double)" (??0?$vtkConstantImplicitBackend@N@@QEAA@N@Z) already defined in vtkToImplicitRamerDouglasPeuckerStrategy.obj
etc ...
...

I could build the library after editing the header file vtkCompositeImplicitBackend.h removing the export from the vtkConstantImplicitBackend struct.
thanks to vividege (fix described above).
C.

Curiously, VTK-9.3 is also not compilable with MinGW64’s GCC in debug mode.