现象:
严重性 代码 说明 项目 文件 行 禁止显示状态 错误 LNK2019 无法解析的外部符号 "__declspec(dllimport) public: static class vtkMatrix4x4 * __cdecl vtkMatrix4x4::New(void)" (__imp_?New@vtkMatrix4x4@@SAPEAV1@XZ),该符号在函数 "public: static class vtkSmartPointer<class vtkMatrix4x4> __cdecl vtkSmartPointer<class vtkMatrix4x4>::New(void)" (?New@?$vtkSmartPointer@VvtkMatrix4x4@@@@SA?AV1@XZ) 中被引用 VTKSample2 F:\VTKFolders\VTKSample2\VTKSample2.obj 1 错误 LNK2019 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl vtkMatrix4x4::DeepCopy(double const * const)" (__imp_?DeepCopy@vtkMatrix4x4@@QEAAXQEBN@Z),该符号在函数 "void __cdecl initImageActor(double *,double *,class vtkSmartPointer<class vtkImageCast>,class vtkSmartPointer<class vtkImageReslice>,class vtkSmartPointer<class vtkImageActor>)" (?initImageActor@@YAXPEAN0V?$vtkSmartPointer@VvtkImageCast@@@@V?$vtkSmartPointer@VvtkImageReslice@@@@V?$vtkSmartPointer@VvtkImageActor@@@@@Z) 中被引用 VTKSample2 F:\VTKFolders\VTKSample2\VTKSample2.obj 1 错误 LNK2019 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl vtkMatrix4x4::SetElement(int,int,double)" (__imp_?SetElement@vtkMatrix4x4@@QEAAXHHN@Z),该符号在函数 "void __cdecl initImageActor(double *,double *,class vtkSmartPointer<class vtkImageCast>,class vtkSmartPointer<class vtkImageReslice>,class vtkSmartPointer<class vtkImageActor>)" (?initImageActor@@YAXPEAN0V?$vtkSmartPointer@VvtkImageCast@@@@V?$vtkSmartPointer@VvtkImageReslice@@@@V?$vtkSmartPointer@VvtkImageActor@@@@@Z) 中被引用 VTKSample2 F:\VTKFolders\VTKSample2\VTKSample2.obj 1 错误 LNK1120 3 个无法解析的外部命令 VTKSample2 F:\VTKFolders\VTK-Build\bin\Debug\VTKSample2.exe 1
这些链接错误表明编译器找到了 vtkMatrix4x4
的声明,但链接器无法找到其实现。这通常是由于项目没有正确链接到所需的 VTK 库。特别是,vtkMatrix4x4
的实现应该在 vtkCommonMath
模块中。
具体解决步骤
-
确认
vtkCommonMath
库的存在:- 确认你的 VTK 安装目录中包含
vtkCommonMath
库文件。库文件通常位于lib
文件夹中,文件名类似于vtkCommonMath-9.3.lib
(版本号可能不同)。
- 确认你的 VTK 安装目录中包含
-
在项目中添加
vtkCommonMath
库:- 在 Visual Studio 项目属性中,添加
vtkCommonMath
库到链接器输入项中。
- 在 Visual Studio 项目属性中,添加
添加库到链接器输入项
-
右键点击项目 -> 属性。
-
转到 配置属性 -> 链接器 -> 输入 -> 附加依赖项。
-
添加
vtkCommonMath
库。例如:vtkCommonMath-9.3.lib
确保添加的库名称与实际安装的 VTK 库文件名称一致。
确认包含和库目录
确保项目属性中的包含目录和库目录已正确设置:
-
右键点击项目 -> 属性。
-
转到 配置属性 -> VC++ 目录。
-
在 包含目录 中添加 VTK 头文件的路径。例如:
C:\Path\To\VTK\include\vtk-9.3
-
在 库目录 中添加 VTK 库文件的路径。例如:
C:\Path\To\VTK\lib
完整的链接库列表
确保链接了所有必要的 VTK 库。以下是一个示例列表(具体库文件名称请参考实际安装的 VTK 版本):
vtkCommonCore-9.3.lib vtkCommonDataModel-9.3.lib vtkCommonMath-9.3.lib vtkRenderingCore-9.3.lib vtkInteractionStyle-9.3.lib vtkRenderingOpenGL2-9.3.lib vtkIOImage-9.3.lib vtkDICOMParser-9.3.lib vtkmetaio-9.3.lib
重新编译
完成上述配置后,重新编译你的项目。如果仍然有问题,请提供更多详细的错误信息,以便进一步诊断和解决。