以前安装VTK很顺,这次VTK安装很不顺。同样都是安装vtk-5.10.1.tar.gz版本,难道因为我这个杂牌的组装电脑配置问题?无论如何,最终还是让我折腾出来了。安装过程涉及库太多,OpenGL,Mesa这2个难点。写在这里,给后来人一点指引,一起探讨。
系统环境:
Ubuntu 12.04.5
CMake 2.8.7
FLTK-1.3.3
Mesa-10.3.5,已安装在/usr/local/Mesa-10.3.5。安装方法见:“编译安装Mesa的详细步骤”。
安装步骤:
1. 下载vtk-5.10.1.tar.gz,地址: http://www.vtk.org/VTK/resources/software.html
2. 拷贝vtk-5.10.1.tar.gz至目录/usr/local/src/下,
sudo tar -xvf vtk-5.10.1.tar.gz
解压后的文件夹名称是: VTK5.10.1,在和它同级的目录建一个binVTK5.10.1文件夹用来编译。
sudo mkdir binVTK5.10.1
cd binVTK5.10.1
sudo ccmake ../VTK5.10.1/
出现如下错误:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENGL_INCLUDE_DIR (ADVANCED)
used as include directory in directory /usr/src/VTK5.10.1
used as include directory in directory /usr/src/VTK5.10.1/Wrapping
used as include directory in directory /usr/src/VTK5.10.1/Utilities
按e键,可以看到提示:
这里有个VTK_DATA_ROOT_NOTFOUND,这个问题完全可以忽略。VTK_DATA_ROOT这里不用设置,也不会影响后面的编译结果的。不过如果你想设置也是可以的,回忆到刚刚下载vtk的网页中有“VTKData”字样的连接供下载,多半有关系,于是回到下载页面,大概如下:
下载“VTKData5.10.1.tar.gz”,并拷贝到目录/install下。解压,将解压后的文件夹路径/install/vtkdata-5.10.1设置到cmake的窗口中的“VTK_DATA_ROOT”和“VTK_LARGE_DATA_ROOT”中(2个一样)。
编译,还是前面一样的错误,一点也不意外!因为这里显然关键问题是缺少OPENGL的一些库文件。需要将Mesa编译后的lib路径设置给vtk。没装Mesa之前,没发现哪里有GL库,Mesa安装以后会出现GL目录(在/usr/local/Mesa-10.3.5/include/目录下)。
这里我已将Mesa安装单独写在另一个帖子中:“编译安装Mesa的详细步骤”。 现假定Mesa已经被成功make install到了/usr/local/Mesa-10.3.5目录。CMake中与该错误相关的条目:
OPENGL_INCLUDE_DIR /usr/local/include
OPENGL_gl_LIBRARY OPENGL_gl_LIBRARY-NOTFOUND
OPENGL_glu_LIBRARY OPENGL_glu_LIBRARY-NOTFOUND
OPENGL_xmesa_INCLUDE_DIR OPENGL_xmesa_INCLUDE_DIR-NOTFOUND
sudo apt-get install libpng-dev libjpeg-dev libxxf86vm1 libxxf86vm-dev libxi-dev libxrandr-dev
装完这个后,重新编译可见下面这2项自动填充了路径:
OPENGL_gl_LIBRARY */usr/local/lib/libGL.so
OPENGL_glu_LIBRARY */usr/lib/x86_64-linux-gnu/libGLU.so
sudo ccmake ../VTK5.10.1/
错误如下:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENGL_gl_LIBRARY (ADVANCED)
linked by target "vtkVolumeRendering" in directory /usr/local/src/VTK5.10.1/VolumeRendering
linked by target "vtkWidgets" in directory /usr/local/src/VTK5.10.1/Widgets
linked by target "RenderingCxxTests" in directory /usr/local/src/VTK5.10.1/Rendering/Testing/Cxx
linked by target "TestFBOImplementation" in directory /usr/local/src/VTK5.10.1/Rendering/Testing/Cxx
linked by target "TimeRenderer" in directory /usr/local/src/VTK5.10.1/Rendering/Testing/Cxx
linked by target "TimeRenderer2" in directory /usr/local/src/VTK5.10.1/Rendering/Testing/Cxx
linked by target "VTKBenchMark" in directory /usr/local/src/VTK5.10.1/Rendering/Testing/Cxx
手动修改这条路径为:
OPENGL_xmesa_INCLUDE_DIR */usr/local/Mesa-10.3.5/include/
sudo ccmake ../VTK5.10.1/
完成,g键,完成。
sudo make
到58%时,出现一个错误如下:
...
[ 52%] Built target vtkGraphics
[ 52%] Built target vtkGenericFiltering
[ 58%] Built target vtkIO
[ 58%] Building CXX object Rendering/CMakeFiles/vtkRendering.dir/vtkXOpenGLRenderWindow.cxx.o
In file included from /usr/local/include/GL/glx.h:333:0,
from /usr/local/src/VTK5.10.1/Rendering/vtkXOpenGLRenderWindow.cxx:31:
/usr/local/include/GL/glxext.h:480:143:error: ‘GLintptr’ has not been declared
typedef void ( *PFNGLXCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
^
/usr/local/include/GL/glxext.h:480:164: error: ‘GLintptr’ has not been declared
typedef void ( *PFNGLXCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
^
/usr/local/include/GL/glxext.h:480:186: error: ‘GLsizeiptr’ has not been declared
typedef void ( *PFNGLXCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
^
/usr/local/include/GL/glxext.h:481:148: error: ‘GLintptr’ has not been declared
typedef void ( *PFNGLXNAMEDCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
^
/usr/local/include/GL/glxext.h:481:169: error: ‘GLintptr’ has not been declared
typedef void ( *PFNGLXNAMEDCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
^
/usr/local/include/GL/glxext.h:481:191: error: ‘GLsizeiptr’ has not been declared
typedef void ( *PFNGLXNAMEDCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
^
make[2]: *** [Rendering/CMakeFiles/vtkRendering.dir/vtkXOpenGLRenderWindow.cxx.o] Error 1
make[1]: *** [Rendering/CMakeFiles/vtkRendering.dir/all] Error 2
make: *** [all] Error 2
test@test:/usr/local/src/binVTK5.10.1$ sudo gedit /usr/local/include/GL/glxext.h
test@tes :/usr/local/src/binVTK5.10.1$ sudo makeGoogle了一下,这应该是新版本的bug,不过vtk user里面高手实在太多了,我在这里https://www.libreoffice.org/bugzilla/show_bug.cgi?id=83631找到解决方法。我是这样解决的:
sudo gedit /usr/local/include/GL/glxext.h
在打开的文件第479行,添加如下2句:
typedef ptrdiff_t GLsizeiptr;
typedef ptrdiff_t GLintptr;
保存,关闭。
因为我的OPENGL_INCLUDE_DIR是设置的指向/usr/local/include,所以我修改/usr/local/include/GL/glxext.h直接就生效了。
sudo make
100%完成。
sudo make install
成功安装完。
最后,附上成功安装的vtk配置全部configure条目:
BUILD_DOCUMENTATION OFF BUILD_EXAMPLES OFF BUILD_SHARED_LIBS OFF BUILD_TESTING ON BZRCOMMAND BZRCOMMAND-NOTFOUND CMAKE_AR /usr/bin/ar CMAKE_BACKWARDS_COMPATIBILITY 2.4 CMAKE_BUILD_TYPE Debug CMAKE_COLOR_MAKEFILE ON CMAKE_CXX_COMPILER /usr/bin/c++ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG -g CMAKE_CXX_FLAGS_MINSIZEREL -Os -DNDEBUG CMAKE_CXX_FLAGS_RELEASE -O3 -DNDEBUG CMAKE_CXX_FLAGS_RELWITHDEBINFO -O2 -g CMAKE_C_COMPILER /usr/bin/gcc CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG -g CMAKE_C_FLAGS_MINSIZEREL -Os -DNDEBUG CMAKE_C_FLAGS_RELEASE -O3 -DNDEBUG CMAKE_C_FLAGS_RELWITHDEBINFO -O2 -g CMAKE_EXE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS_DEBUG CMAKE_EXE_LINKER_FLAGS_MINSIZE CMAKE_EXE_LINKER_FLAGS_RELEASE CMAKE_EXE_LINKER_FLAGS_RELWITH CMAKE_EXPORT_COMPILE_COMMANDS OFF CMAKE_HP_PTHREADS OFF CMAKE_INSTALL_PREFIX /usr/local/vtk-10.5.1 CMAKE_LINKER /usr/bin/ld CMAKE_MAKE_PROGRAM /usr/bin/make CMAKE_MODULE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS_DEBU CMAKE_MODULE_LINKER_FLAGS_MINS CMAKE_MODULE_LINKER_FLAGS_RELE CMAKE_MODULE_LINKER_FLAGS_RELW CMAKE_NM /usr/bin/nm CMAKE_OBJCOPY /usr/bin/objcopy CMAKE_OBJDUMP /usr/bin/objdump CMAKE_RANLIB /usr/bin/ranlib CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS_DEBU CMAKE_SHARED_LINKER_FLAGS_MINS CMAKE_SHARED_LINKER_FLAGS_RELE CMAKE_SHARED_LINKER_FLAGS_RELW CMAKE_SKIP_RPATH OFF CMAKE_STRIP /usr/bin/strip CMAKE_THREAD_LIBS -lpthread CMAKE_USE_PTHREADS ON CMAKE_USE_RELATIVE_PATHS OFF CMAKE_USE_SPROC OFF CMAKE_USE_WIN32_THREADS OFF CMAKE_VERBOSE_MAKEFILE OFF CMAKE_X_CFLAGS CMAKE_X_LIBS /usr/lib/x86_64-linux-gnu/libSM.so;/usr/lib/x86_64-linux-gnu/libICE.so;/usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so COVERAGE_COMMAND /usr/bin/gcov COVERAGE_EXTRA_FLAGS -l CTEST_SUBMIT_RETRY_COUNT 3 CTEST_SUBMIT_RETRY_DELAY 5 CVSCOMMAND CVSCOMMAND-NOTFOUND CVS_UPDATE_OPTIONS -d -A -P DART_TESTING_TIMEOUT 1500 EXODUSII_DISABLE_COMPILER_WARN ON GITCOMMAND /usr/bin/git HDF5_BUILD_CPP_LIB OFF HDF5_BUILD_HL_LIB ON HDF5_DISABLE_COMPILER_WARNINGS ON HDF5_ENABLE_HSIZET ON HDF5_ENABLE_LARGE_FILE ON HDF5_ENABLE_PARALLEL OFF HDF5_ENABLE_SZIP_SUPPORT OFF HDF5_ENABLE_Z_LIB_SUPPORT ON HDF5_Enable_Clear_File_Buffers ON HDF5_Enable_Instrument OFF HDF5_METADATA_TRACE_FILE OFF HDF5_STRICT_FORMAT_CHECKS OFF HDF5_USE_16_API_DEFAULT OFF HDF5_USE_FILTER_FLETCHER32 ON HDF5_USE_FILTER_NBIT ON HDF5_USE_FILTER_SCALEOFFSET ON HDF5_USE_FILTER_SHUFFLE ON HDF5_USE_H5DUMP_PACKED_BITS ON HDF5_WANT_DATA_ACCURACY ON HDF5_WANT_DCONV_EXCEPTION ON HGCOMMAND HGCOMMAND-NOTFOUND MAKECOMMAND /usr/bin/make -i MEMORYCHECK_COMMAND MEMORYCHECK_COMMAND-NOTFOUND MEMORYCHECK_SUPPRESSIONS_FILE NETCDF4_CHUNK_CACHE_NELEMS 1009 NETCDF4_CHUNK_CACHE_PREEMPTION 0.75 NETCDF4_CHUNK_CACHE_SIZE 4194304 NETCDF4_DEFAULT_CHUNKS_IN_CACH 10 NETCDF4_DEFAULT_CHUNK_SIZE 4194304 NETCDF4_MAX_DEFAULT_CACHE_SIZE 67108864 NETCDF_DISABLE_COMPILER_WARNIN ON NETCDF_ENABLE_CXX ON NETCDF_ENABLE_NETCDF4 ON OPENGL_INCLUDE_DIR /usr/local/include OPENGL_gl_LIBRARY /usr/local/lib/libGL.so OPENGL_glu_LIBRARY /usr/lib/x86_64-linux-gnu/libGLU.so OPENGL_xmesa_INCLUDE_DIR /usr/local/Mesa-10.3.5/include PROJ_LIST_EXTERNAL OFF PROJ_USE_GSL OFF PROJ_USE_PTHREADS OFF PYTHON_EXECUTABLE /usr/bin/python SCPCOMMAND /usr/bin/scp SITE pangolin SLURM_SBATCH_COMMAND SLURM_SBATCH_COMMAND-NOTFOUND SLURM_SRUN_COMMAND SLURM_SRUN_COMMAND-NOTFOUND SVNCOMMAND SVNCOMMAND-NOTFOUND VERDICT_BUILD_DOC OFF VERDICT_ENABLE_TESTING OFF VERDICT_MANGLE ON VERDICT_MANGLE_PREFIX vtk VERDICT_USE_FLOAT OFF VLI_LIBRARY_FOR_VP1000 VLI_LIBRARY_FOR_VP1000-NOTFOUND VTK_BUILD_FORWARDING_EXECUTABL OFF VTK_DATA_ROOT /install/VTKData5.10.1/ VTK_DEBUG_LEAKS OFF VTK_EXTRA_COMPILER_WARNINGS OFF VTK_GLEXT_FILE /usr/local/src/VTK5.10.1/Utilities/ParseOGLExt/headers/glext.h VTK_GLXEXT_FILE /usr/local/src/VTK5.10.1/Utilities/ParseOGLExt/headers/glxext.h VTK_IGNORE_BTX ON VTK_INSTALL_THIRD_PARTY_LIBRAR OFF VTK_LARGE_DATA_ROOT /install/VTK5.10.1/ VTK_LEGACY_REMOVE OFF VTK_LEGACY_SILENT OFF VTK_MATERIALS_DIRS /usr/local/src/binVTK5.10.1/Utilities/MaterialLibrary/Repository VTK_MAX_THREADS 64 VTK_OPENGL_HAS_OSMESA OFF VTK_TESTING_LOCALE VTK_TESTING_USE_FPE ON VTK_TESTING_USE_LOCALE OFF VTK_USE_64BIT_IDS ON VTK_USE_BOOST OFF VTK_USE_CG_SHADERS OFF VTK_USE_CHARTS ON VTK_USE_CHEMISTRY OFF VTK_USE_DISPLAY ON VTK_USE_FFMPEG_ENCODER OFF VTK_USE_GCC_VISIBILITY ON VTK_USE_GEOVIS ON VTK_USE_GL2PS OFF VTK_USE_GLSL_SHADERS ON VTK_USE_GNU_R OFF VTK_USE_GUISUPPORT OFF VTK_USE_INFOVIS ON VTK_USE_MANGLED_MESA OFF VTK_USE_MATLAB_MEX OFF VTK_USE_METAIO ON VTK_USE_MPEG2_ENCODER OFF VTK_USE_MYSQL OFF VTK_USE_NVCONTROL OFF VTK_USE_N_WAY_ARRAYS ON VTK_USE_ODBC OFF VTK_USE_OGGTHEORA_ENCODER OFF VTK_USE_PARALLEL OFF VTK_USE_POSTGRES OFF VTK_USE_QT OFF VTK_USE_RENDERING ON VTK_USE_SYSTEM_EXPAT OFF VTK_USE_SYSTEM_FREETYPE OFF VTK_USE_SYSTEM_HDF5 OFF VTK_USE_SYSTEM_JPEG OFF VTK_USE_SYSTEM_LIBPROJ4 OFF VTK_USE_SYSTEM_LIBXML2 OFF VTK_USE_SYSTEM_PNG OFF VTK_USE_SYSTEM_TIFF OFF VTK_USE_SYSTEM_ZLIB OFF VTK_USE_TDX OFF VTK_USE_TEXT_ANALYSIS OFF VTK_USE_VIEWS ON VTK_USE_VOLUMEPRO_1000 OFF VTK_WGLEXT_FILE /usr/local/src/VTK5.10.1/Utilities/ParseOGLExt/headers/wglext.h VTK_WRAP_HINTS /usr/local/src/VTK5.10.1/Wrapping/hints VTK_WRAP_JAVA OFF VTK_WRAP_PYTHON OFF VTK_WRAP_PYTHON_SIP OFF VTK_WRAP_TCL OFF X11_ICE_INCLUDE_PATH /usr/include X11_ICE_LIB /usr/lib/x86_64-linux-gnu/libICE.so X11_SM_INCLUDE_PATH /usr/include X11_SM_LIB /usr/lib/x86_64-linux-gnu/libSM.so X11_X11_INCLUDE_PATH /usr/include X11_X11_LIB /usr/lib/x86_64-linux-gnu/libX11.so X11_XRes_INCLUDE_PATH /usr/include X11_XRes_LIB /usr/lib/libXRes.so X11_XShm_INCLUDE_PATH /usr/include X11_XSync_INCLUDE_PATH /usr/include X11_XTest_INCLUDE_PATH /usr/include X11_XTest_LIB /usr/lib/x86_64-linux-gnu/libXtst.so X11_Xaccessrules_INCLUDE_PATH /usr/include X11_Xaccessstr_INCLUDE_PATH /usr/include X11_Xau_INCLUDE_PATH /usr/include X11_Xau_LIB /usr/lib/x86_64-linux-gnu/libXau.so X11_Xcomposite_INCLUDE_PATH /usr/include X11_Xcomposite_LIB /usr/lib/x86_64-linux-gnu/libXcomposite.so X11_Xcursor_INCLUDE_PATH /usr/include X11_Xcursor_LIB /usr/lib/x86_64-linux-gnu/libXcursor.so X11_Xdamage_INCLUDE_PATH /usr/include X11_Xdamage_LIB /usr/lib/x86_64-linux-gnu/libXdamage.so X11_Xdmcp_INCLUDE_PATH /usr/include X11_Xdmcp_LIB /usr/lib/x86_64-linux-gnu/libXdmcp.so X11_Xext_LIB /usr/lib/x86_64-linux-gnu/libXext.so X11_Xfixes_INCLUDE_PATH /usr/include X11_Xfixes_LIB /usr/lib/x86_64-linux-gnu/libXfixes.so X11_Xft_INCLUDE_PATH /usr/include X11_Xft_LIB /usr/lib/x86_64-linux-gnu/libXft.so X11_Xi_INCLUDE_PATH /usr/include X11_Xi_LIB /usr/lib/x86_64-linux-gnu/libXi.so X11_Xinerama_INCLUDE_PATH /usr/include X11_Xinerama_LIB /usr/lib/x86_64-linux-gnu/libXinerama.so X11_Xinput_INCLUDE_PATH /usr/include X11_Xinput_LIB /usr/lib/x86_64-linux-gnu/libXi.so X11_Xkb_INCLUDE_PATH /usr/include X11_Xkbfile_INCLUDE_PATH /usr/include X11_Xkbfile_LIB /usr/lib/x86_64-linux-gnu/libxkbfile.so X11_Xkblib_INCLUDE_PATH /usr/include X11_Xlib_INCLUDE_PATH /usr/include X11_Xpm_INCLUDE_PATH /usr/include X11_Xpm_LIB /usr/lib/x86_64-linux-gnu/libXpm.so X11_Xrandr_INCLUDE_PATH /usr/include X11_Xrandr_LIB /usr/lib/x86_64-linux-gnu/libXrandr.so X11_Xrender_INCLUDE_PATH /usr/include X11_Xrender_LIB /usr/lib/x86_64-linux-gnu/libXrender.so X11_Xscreensaver_INCLUDE_PATH /usr/include X11_Xscreensaver_LIB /usr/lib/x86_64-linux-gnu/libXss.so X11_Xshape_INCLUDE_PATH /usr/include X11_Xt_INCLUDE_PATH /usr/include X11_Xt_LIB /usr/lib/x86_64-linux-gnu/libXt.so X11_Xutil_INCLUDE_PATH /usr/include X11_Xv_INCLUDE_PATH /usr/include X11_Xv_LIB /usr/lib/x86_64-linux-gnu/libXv.so X11_Xxf86misc_LIB X11_Xxf86misc_LIB-NOTFOUND X11_dpms_INCLUDE_PATH /usr/include X11_xf86misc_INCLUDE_PATH X11_xf86misc_INCLUDE_PATH-NOTFOUND X11_xf86vmode_INCLUDE_PATH /usr/include
推荐2个可以供你搜集宏观思路的比较全的安装步骤:
http://www.cnblogs.com/ankier/archive/2012/11/09/2763400.html
http://blog.sina.com.cn/s/blog_76e94d21010107fh.html