问题
I'm new to vtk, so I started by building vtk 8.1.1 with CMake and Visual Studio 2017, with the default options and the examples.
Many of the examples runs fine, but some of them gives an error:
This one is the CreateTree example, but the HelloWorld gives the same error.
I don't know if it has something to do with this issue.
I've also tried the solution from this question and this one. But when I add
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
right after all the includes, Visual Studio gives me this error:
1>CreateTree.obj : error LNK2019: unresolved external symbol "void __cdecl vtkRenderingOpenGL2_AutoInit_Construct(void)" (?vtkRenderingOpenGL2_AutoInit_Construct@@YAXXZ) referenced in function "public: __thiscall vtkRenderingOpenGL2_ModuleInit::vtkRenderingOpenGL2_ModuleInit(void)" (??0vtkRenderingOpenGL2_ModuleInit@@QAE@XZ)
1>CreateTree.obj : error LNK2019: unresolved external symbol "void __cdecl vtkRenderingOpenGL2_AutoInit_Destruct(void)" (?vtkRenderingOpenGL2_AutoInit_Destruct@@YAXXZ) referenced in function "public: __thiscall vtkRenderingOpenGL2_ModuleInit::~vtkRenderingOpenGL2_ModuleInit(void)" (??1vtkRenderingOpenGL2_ModuleInit@@QAE@XZ)
1>C:\vtkSource\bin\bin\Debug\CreateTree.exe : fatal error LNK1120: 2 unresolved externals
if I try VTK_MODULE_INIT(vtkRenderingWindow)
or VTK_MODULE_INIT(vtkRenderingOpenGL)
I get the same errors.
Also, examples like Delaunay3D only open a window that closes so fast I can't even see what it does have.
回答1:
Did you try adding the following line
vtkRendering${VTK_RENDERING_BACKEND}
to the set(VTK_Modules ...)
command in the CMakeLists.txt
for the HelloWorld
or CreateTree
projects just like it is suggested in the link you posted.
EDIT
Just to expand the explanation for beginners, the CMakeLists.txt
is the path VTK-8.1.1\Examples\Infovis\Cxx
. And the file should look like this:
来源:https://stackoverflow.com/questions/51796656/error-with-vtkrenderer