3D Slicer 4.7.0 VS 2010 Compile 编译

本文记录了作者在VS2010上成功编译3DSlicer4.7.0的过程及心得。面对庞大的外部库与漫长的编译时间,作者分享了关键步骤与解决编译过程中遇到的具体错误的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

花了将近一周的时间的,终于在VS2010成功的编译了最新版的3D Slicer 4.7.0,感觉快要崩溃了。Slicer用了20多个外部的库,全都要一起编译,完整编译一次起码要七八个小时,光VS的Output输出窗口有十万多行,复制到txt中,文本内容居然有26MB之多,可怕!经过台式机和笔记本分别进行多次编译,出错,改错,再编译,再出错,再改错。。。总共编译了有二三十次,终于在台式机上成功了编译了Slicer,感觉眼泪都要掉下来了,下面整理下成功编译的心得,希望给他人开路,不要再像博主这样无数次尝试:

1. 下载Slicer的最新代码 (https://github.com/Slicer/Slicer)

2. 下载Qt 4.8.6 (https://download.qt.io/archive/qt/4.8/4.8.6/),博主编译的是32位的,所以这里下载的是x86-vs2010版本的

3. 下载最新版的CMake 3.7.2, 注意这里一定要下载最新版本的,因为用老版本很可能会出错!

4. Slicer的编译路径要尽可能的短,最好就放在某个盘的根目录,比如code放在 C:/Slicer,编译的文件放在C:/build。(血与泪的教训啊,如果路径名太长,会在编译的时候可能会找不到某些头文件)

5. 在用Cmake配置的时候,取消 Unselect Slicer_USE_NUMPY, 因为编译这个很有可能会出错,而且一般情况下我们用不上,所以不用选。

6. 然后就是在打开Slicer.sln后,选择Release模式,进行编译。

下面是楼主在编译的过程中遇到的错误,以及改正方法:

Error 1:

44>C:\Slicer\libs\vtkitk\itkMorphologicalContourInterpolator.hxx(150): error C2668: 'pow' : ambiguous call to overloaded function [C:\build\Slicer-build\Libs\vtkITK\vtkITK.vcxproj]
44>C:\Slicer\libs\vtkitk\itkMorphologicalContourInterpolator.hxx(153): fatal error C1903: unable to recover from previous error(s); stopping compilation [C:\build\Slicer-build\Libs\vtkITK\vtkITK.vcxproj]

Change:

m_MinAlignIters( pow( 2, TImage::ImageDimension ) ), // smaller of this and pixel count of the search image

to:

m_MinAlignIters( pow( 2, (double)TImage::ImageDimension ) ), // smaller of this and pixel count of the search image

Change:

m_MaxAlignIters( pow( 6, TImage::ImageDimension ) ), // bigger of this and root of pixel count of the search image

to:

m_MaxAlignIters( pow( 6, (double)TImage::ImageDimension ) ), // bigger of this and root of pixel count of the search image

Error 2:

4>..\..\..\..\Slicer\Libs\vtkAddon\vtkAddonMathUtilities.cxx(264): error C2668: 'sqrt' : ambiguous call to overloaded function [C:\build\Slicer-build\Libs\vtkAddon\vtkAddon.vcxproj]
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(127): could be 'double sqrt(double)'
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(541): or       'float sqrt(float)'
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(589): or       'long double sqrt(long double)'
44>            while trying to match the argument list '(unsigned __int64)'

Change:

int dimension = std::sqrt(elements.size()) + 0.5; // Since conversion to int just truncates

to:

int dimension = std::sqrt((double)elements.size()) + 0.5; // Since conversion to int just truncates

Error 3:

44>C:\Slicer\libs\vtkitk\itkMorphologicalContourInterpolator.hxx(1284): error C2668: 'sqrt' : ambiguous call to overloaded function [C:\build\Slicer-build\Libs\vtkITK\vtkITK.vcxproj]
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(589): could be 'long double sqrt(long double)'
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(541): or       'float sqrt(float)'
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(127): or       'double sqrt(double)'
44>            while trying to match the argument list '(unsigned long)'
44>            C:\Slicer\libs\vtkitk\itkMorphologicalContourInterpolator.hxx(1243) : while compiling class template member function 'itk::Index<VIndexDimension> itk::MorphologicalContourInterpolator<TImage>::Align(itk::SmartPointer<TObjectType> &,long,itk::SmartPointer<TObjectType> &,const std::vector<_Ty> &)'

Change:

IdentifierType maxIter = std::max( m_MaxAlignIters, (IdentifierType)sqrt( searchRegion.GetNumberOfPixels() ) );

to:

IdentifierType maxIter = std::max( m_MaxAlignIters, (IdentifierType)sqrt( (double)searchRegion.GetNumberOfPixels() ) );

Error 4:

44>..\..\..\..\..\..\Slicer\Libs\MRML\Core\Testing\vtkMRMLSceneTest2.cxx(41): error C2039: 'back_inserter' : is not a member of 'std' [C:\build\Slicer-build\Libs\MRML\Core\Testing\MRMLCoreCxxTests.vcxproj]
44>..\..\..\..\..\..\Slicer\Libs\MRML\Core\Testing\vtkMRMLSceneTest2.cxx(41): error C3861: 'back_inserter': identifier not found [C:\build\Slicer-build\Libs\MRML\Core\Testing\MRMLCoreCxxTests.vcxproj]

Add:

#include <iterator>

Error 5:

44>..\..\..\..\..\..\Slicer\Modules\Loadable\Segmentations\EditorEffects\qSlicerSegmentEditorScissorsEffect.cxx(389): error C2668: 'sqrt' : ambiguous call to overloaded function [C:\build\Slicer-build\Modules\Loadable\Segmentations\EditorEffects\qSlicerSegmentationsEditorEffects.vcxproj]
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(589): could be 'long double sqrt(long double)'
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(541): or       'float sqrt(float)'
44>            c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(127): or       'double sqrt(double)'
44>            while trying to match the argument list '(int)'

Change:

double radius = sqrt((eventPosition[0] - this->DragStartPosition[0])*(eventPosition[0] - this->DragStartPosition[0])
          + (eventPosition[1] - this->DragStartPosition[1])*(eventPosition[1] - this->DragStartPosition[1]));

to:

double radius = sqrt((double)(eventPosition[0] - this->DragStartPosition[0])*(eventPosition[0] - this->DragStartPosition[0])
          + (eventPosition[1] - this->DragStartPosition[1])*(eventPosition[1] - this->DragStartPosition[1]));

Error 6:

'ACPCTransformCLP.h': No such file or directory
'AddScalarVolumesCLP.h': No such file or directory
'BRAINSDWICleanupCLP.h': No such file or directory
'BRAINSDemonWarpCLP.h': No such file or directory
'BRAINSFitCLP.h': No such file or directory
'BRAINSLabelStatsCLP.h': No such file or directory
'BRAINSROIAutoCLP.h': No such file or directory
'BRAINSResampleCLP.h': No such file or directory
'BRAINSResizeCLP.h': No such file or directory
'BRAINSStripRotationCLP.h': No such file or directory
'BRAINSTransformConvertCLP.h': No such file or directory
'BSplineToDeformationFieldCLP.h': No such file or directory
'CLIModule4TestCLP.h': No such file or directory
'CLIROITestCLP.h': No such file or directory
'CastScalarVolumeCLP.h': No such file or directory
'CheckerBoardFilterCLP.h': No such file or directory
'CreateDICOMSeriesCLP.h': No such file or directory
'CurvatureAnisotropicDiffusionCLP.h': No such file or directory
'DWIConvertCLP.h': No such file or directory
'DiffusionTensorTestCLP.h': No such file or directory
'EMSegmentCommandLineCLP.h': No such file or directory
'EMSegmentTransformToNewFormatCLP.h': No such file or directory
'ExecutionModelTourCLP.h': No such file or directory
'ExpertAutomatedRegistrationCLP.h': No such file or directory
'ExtractSkeletonCLP.h': No such file or directory
'FiducialRegistrationCLP.h': No such file or directory
'GaussianBlurImageFilterCLP.h': No such file or directory
'GradientAnisotropicDiffusionCLP.h': No such file or directory
'GrayscaleFillHoleImageFilterCLP.h': No such file or directory
'GrayscaleGrindPeakImageFilterCLP.h': No such file or directory
'GrayscaleModelMakerCLP.h': No such file or directory
'HistogramMatchingCLP.h': No such file or directory
'ImageLabelCombineCLP.h': No such file or directory
'IslandRemovalCLP.h': No such file or directory
'LabelMapSmoothingCLP.h': No such file or directory
'MaskScalarVolumeCLP.h': No such file or directory
'MedianImageFilterCLP.h': No such file or directory
'MergeModelsCLP.h': No such file or directory
'ModelMakerCLP.h': No such file or directory
'ModelToLabelMapCLP.h': No such file or directory
'MultiplyScalarVolumesCLP.h': No such file or directory
'N4ITKBiasFieldCorrectionCLP.h': No such file or directory
'OrientScalarVolumeCLP.h': No such file or directory
'OtsuThresholdImageFilterCLP.h': No such file or directory
'PETStandardUptakeValueComputationCLP.h': No such file or directory
'PerformMetricTestCLP.h': No such file or directory
'ProbeVolumeWithModelCLP.h': No such file or directory
'ResampleDTIVolumeCLP.h': No such file or directory
'ResampleScalarVectorDWIVolumeCLP.h': No such file or directory
'ResampleScalarVolumeCLP.h': No such file or directory
'RobustStatisticsSegmenterCLP.h': No such file or directory
'SimpleRegionGrowingSegmentationCLP.h': No such file or directory
'SubtractScalarVolumesCLP.h': No such file or directory
'TestGridTransformRegistrationCLP.h': No such file or directory
'ThresholdScalarVolumeCLP.h': No such file or directory
'VBRAINSDemonWarpCLP.h': No such file or directory
'VotingBinaryHoleFillingImageFilterCLP.h': No such file or directory

Solution:

Make the path short for CMake! For example, put Slicer source code at C:/Slicer, put the build files at C:/build

成功编译后得到如图所示的界面:

本文转自博客园Grandyang的博客,原文链接:3D Slicer 4.7.0 VS 2010 Compile 编译,如需转载请自行联系原博主。

编译 3D Slicer 源代码是一个较为复杂的过程,涉及多个依赖库的下载与配置。以下为基于不同操作系统的编译流程概述,以及常见注意事项。 ### 编译环境准备 #### Windows 系统 在 Windows 上编译 3D Slicer 通常使用 Visual Studio,推荐版本为 VS2015 或更高。此外,还需要安装以下工具链: - **Qt 5.9.3**:用于图形界面开发。 - **Git 2.16.1** 或更高版本:用于源码版本控制。 - **CMake 3.14.1** 或更高版本:用于生成构建配置。 - **NSIS (Unicode)**:用于打包安装程序。 #### Linux 系统(以 Ubuntu 为例) 在 Ubuntu 上编译 3D Slicer 通常使用 CMake 和 Make 工具。所需依赖包括: - **Git**:用于获取源码。 - **CMake**:用于构建配置。 - **GCC 或 Clang**:用于编译。 - **Qt5 开发库**:如 `libqt5-dev`。 - **Python 3.x**:用于脚本支持。 ### 获取源代码 从 GitHub 官方仓库获取 3D Slicer 的源代码: ```bash git clone https://github.com/Slicer/Slicer.git cd Slicer ``` 由于源码依赖众多第三方库,克隆过程可能会较慢,尤其是在网络条件不佳的情况下。建议使用代理或镜像加速下载 [^5]。 ### 配置构建环境 #### 使用 CMake 配置 创建一个独立的构建目录,并进入该目录进行配置: ```bash mkdir build cd build cmake -G "Visual Studio 14 2015 Win64" .. # Windows 示例 # 或者 cmake -G "Unix Makefiles" .. # Linux 示例 ``` CMake 会自动下载并构建所需的第三方库(通过 Superbuild 机制),这一步可能需要较长时间,且依赖网络稳定性 [^3]。 #### 编译构建 配置完成后,执行编译命令: ```bash cmake --build . --config Release # 或者使用平台特定命令 make -j$(nproc) # Linux ``` 在 Windows 上,可以使用 Visual Studio 打开生成的 `.sln` 文件,选择适当的配置(Debug 或 Release)进行构建 [^4]。 ### 常见问题与解决方案 - **依赖库下载失败**:由于 3D Slicer 依赖多达 50 个外部库,网络不稳定可能导致下载失败。建议使用代理或手动下载并放置到指定目录。 - **Qt 版本不兼容**:确保使用的 Qt 版本与官方推荐一致,避免因版本差异导致构建失败。 - **CMake 配置错误**:检查 CMake 的路径设置,确保所有依赖库路径正确无误。 - **Visual Studio 版本不匹配**:确保使用的 Visual Studio 版本与 CMake 生成器匹配。 ### 调试与测试 构建完成后,可在构建目录中找到可执行文件 `Slicer.exe`(Windows)或 `Slicer`(Linux)。启动后,验证基本功能是否正常,如图像加载、分割工具等 [^1]。 ### 示例代码:启动 Slicer 并加载模块 ```python # 示例:通过 Python 脚本加载模块 import slicer # 加载某个模块 module = slicer.modules.volumes module.logic().AddVolume("path/to/image.nii") ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值