unresolved external symbol "void __cdecl vtkRenderingVolume_AutoInit_Construct(void)"

I am getting this error, vtk-9.5, static libs build with VS under WIndows10.

I googled the issue, AI suggested that VTK uses dynamic linking to link the rendering backend at runtime and with static linking that does not take place. It suggested I add these lines to the file where the rendering code is

#include <vtkAutoInit.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2);

VTK_MODULE_INIT(vtkRenderingVolume);

I did and that did not work. The next thing was to add these preprocessor directives:

vtkRenderingOpenGL2_AUTOINIT=1(vtkRenderingGL2PSOpenGL2) vtkVolumeRenderingOpenGL2_AUTOINIT=1(vtkRenderingVolumeOpenGL2)

It did not work too.

Any ideas how to fix this issue?

Hi @jsemeda :waving_hand:. Could you please share the CMake flags used to build VTK? Also, the error is not visible in the original post. Could you please reshare?

I think your edits are in the right direction, but you also need to link to the targets involved in providing those factories. You’re probably missing a vtk_module_autoinit call in your CMake code.

How should I do that? Does attaching the cmake file here help?

The full error is :

error LNK2019: unresolved external symbol “void __cdecl vtkVolumeRenderingOpenGL2_AutoInit_Construct(void)” (?vtkVolumeRenderingOpenGL2_AutoInit_Construct@@YAXXZ) referenced in function “public: __cdecl `anonymous namespace’::vtkVolumeRenderingOpenGL2_ModuleInit::vtkVolumeRenderingOpenGL2_ModuleInit(void)” (??0vtkVolumeRenderingOpenGL2_ModuleInit@?A0x43c0deb8@@QEAA@XZ)

I added

# Enable auto-initialization for the target and modules

vtk_module_autoinit(

TARGETS MyVTKApp

MODULES ${VTK_LIBRARIES}

)

but it did not help. I tried replacing the ${VTK_LIBRARIES} with the missing module name from the error, vtkVolumeRenderingOpenGL2, but it gave an error in the cmake file.

I also tried

vtk_module_autoinit(
TARGETS dicom2meshlib
MODULES vtk::CommonCore
vtk::RenderingCore
vtk::RenderingOpenGL2
vtk::RenderingVolume
vtk::RenderingVolumeOpenGL2
vtk::InteractionStyle
)

did not work. I am following what is in the documentaion, but maybe the way I am listing the modules is not correct? Maybe the module names? although when I write this in the cmake file the autocomplete is listing these modules as written.

I’ve seen this in the past when devs try to write the module init themselves and fumble on the module names.

vtkVolumeRenderingOpenGL2_AUTOINIT=1(vtkRenderingVolumeOpenGL2)

You’ve transposed the module name. It should be vtkRenderingVolumeOpenGL2_AUTOINIT=... That might explain why you saw error LNK2019: unresolved external symbol “void __cdecl vtkVolumeRenderingOpenGL2_AutoInit_Construct.

When you tried autoinit, did you remove the manual module init and try again? Maybve stale VTK_AUTOINIT define in cache/add_definitions from incorrect build is being carried forward. Try to delete your build directory and re-configure from scratch using the autoinit.

What I can suggest to you is don’t hand-write VTK_MODULE_INIT / VTK_AUTOINIT defines. Let CMake do it. Call find_package with the components you need. They will be placed in VTK_LIBRARIES

# CMakeLists.txt
find_package(VTK REQUIRED COMPONENTS
  CommonCore
  InterationStyle
  RenderingCore
  RenderingVolume
  RenderingVolumeOpenGL2
  RenderingOpenGL2
)
target_link_libraries(dicom2meshlib PRIVATE ${VTK_LIBRARIES}) # needed
vtk_module_autoinit(TARGETS dicom2meshlib MODULES ${VTK_LIBRARIES}) # also needed