这个是自己配置的方法。其实bestway是使用CMakeLists来帮你配置项目~。。这个就不写了。。因为懒。。哈哈
1.新建->项目->Visual C++ ->Win32控制台应用程序->test1。选择为->空项目。不然还要删文件。。
2.选择项目->新建->test.cpp
3.拷贝以下代码
1 #include "vtkConeSource.h" 2 #include "vtkPolyDataMapper.h" 3 #include "vtkRenderWindow.h" 4 #include "vtkCamera.h" 5 #include "vtkActor.h" 6 #include "vtkRenderer.h" 7 #include "vtkProperty.h" 8 int main() 9 { 10 vtkConeSource *cone = vtkConeSource::New(); 11 cone->SetHeight( 3.0 ); 12 cone->SetRadius( 1.0 ); 13 cone->SetResolution( 10 ); 14 vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); 15 coneMapper->SetInputConnection( cone->GetOutputPort() ); 16 vtkActor *coneActor = vtkActor::New(); 17 coneActor->SetMapper( coneMapper ); 18 vtkRenderer *ren1= vtkRenderer::New(); 19 ren1->AddActor( coneActor ); 20 ren1->SetBackground( 0.1, 0.2, 0.4 ); 21 vtkRenderWindow *renWin = vtkRenderWindow::New(); 22 renWin->AddRenderer( ren1 ); 23 renWin->SetSize( 300, 300 ); 24 int i; 25 for (i = 0; i < 360; ++i) 26 { 27 renWin->Render(); 28 ren1->GetActiveCamera()->Azimuth( i ); 29 } 30 cone->Delete(); 31 coneMapper->Delete(); 32 coneActor->Delete(); 33 ren1->Delete(); 34 renWin->Delete(); 35 return 0; 36 }
4.项目->test1属性->C/C++->常规->附加包含目录->
从安装的实例中拷贝路径。粘贴即可。
我这里是
D:/vtk/bin;D:/vtk/bin/Common;D:/vtk/bin/Utilities;D:/vtk/bin/VolumeRendering;D:/vtk/bin/Rendering;D:/vtk/bin/Charts;D:/vtk/bin/GUISupport/MFC;D:/vtk/bin/Utilities/vtkalglib;D:/vtk/sourcecode/Infovis;D:/vtk/sourcecode/Geovis;D:/vtk/sourcecode/Views;D:/vtk/sourcecode/Parallel;D:/vtk/sourcecode/VolumeRendering;D:/vtk/sourcecode/Hybrid;D:/vtk/sourcecode/Widgets;D:/vtk/sourcecode/Rendering;D:/vtk/sourcecode/Charts;D:/vtk/sourcecode/Rendering/Testing/Cxx;D:/vtk/sourcecode/IO;D:/vtk/sourcecode/Imaging;D:/vtk/sourcecode/Graphics;D:/vtk/sourcecode/GenericFiltering;D:/vtk/sourcecode/Filtering;D:/vtk/sourcecode/Common;D:/vtk/sourcecode/Utilities;D:/vtk/sourcecode/Common/Testing/Cxx;D:/vtk/bin/Utilities/vtklibproj4;D:/vtk/sourcecode/Utilities/vtklibproj4;D:/vtk/bin/Utilities/DICOMParser;D:/vtk/sourcecode/Utilities/DICOMParser;D:/vtk/bin/Utilities/vtkfreetype/include;D:/vtk/sourcecode/Utilities/vtkfreetype/include;D:/vtk/bin/Utilities/MaterialLibrary;D:/vtk/sourcecode/Utilities/MaterialLibrary;D:/vtk/bin/Utilities/verdict;D:/vtk/sourcecode/Utilities/verdict;D:/vtk/bin/Utilities/vtkhdf5;D:/vtk/sourcecode/Utilities/vtkhdf5;D:/vtk/bin/Utilities/vtkhdf5/src;D:/vtk/sourcecode/Utilities/vtkhdf5/src;D:/vtk/bin/Utilities/Cosmo;D:/vtk/sourcecode/Utilities/Cosmo;D:/vtk/bin/Utilities/VPIC;D:/vtk/sourcecode/Utilities/VPIC;D:/vtk/sourcecode/Utilities/utf8/source;D:/vtk/sourcecode/GUISupport/MFC;D:/vtk/sourcecode/Utilities/vtkalglib;D:/vtk/sourcecode/Utilities/ftgl/src;D:/vtk/bin/Utilities/ftgl;%(AdditionalIncludeDirectories)
5。还是项目选项卡->test1属性->链接器->输入->附加依赖项
还是复制啊粘贴:
opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;vtkCommon.lib;vtkDICOMParser.lib;vtkexoIIc.lib;vtkexpat.lib;vtkFiltering.lib;vtkfreetype.lib;vtkftgl.lib;vtkGenericFiltering.lib;vtkGraphics.lib;vtkHybrid.lib;vtkImaging.lib;vtkIO.lib;vtkjpeg.lib;vtkNetCDF.lib;vtkpng.lib;vtkRendering.lib;vtksys.lib;vtktiff.lib;vtkVolumeRendering.lib;vtkWidgets.lib;vtkzlib.lib
6.但是只有上一步还不够,编译会提示——fatal error LNK1104: 无法打开文件“xx.lib”
于是有几个方法解决。。第一个
连接器-》常规-》附加库目录。。添加包含.lib文件的那个目录的绝对路径即可。。第二个,可以把需要包含的lib复制到你的test1文件夹下面。。==笨~
7.编译运行结果