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:
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.
# 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.
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.
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