Failed to build Slicer cause the CTK.build exited with code 1

Hello,

I have been attempting to build the latest version of Slicer over the past few days, but I encountered a failure when trying to build CTK. And here is the error log what I received.

CMake = 3.28.1
Visual studio = 2022 , toolset v143
QT = 5.15.2
OS = WIindows 11 pro 23H2

      1>Checking Build System
      CTKCore.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKCore.dll
      CTKCorePythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKCorePythonQt.pyd
      CTKDICOMCore.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKDICOMCore.dll
      CTKDICOMCorePythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKDICOMCorePythonQt.pyd
      CTKWidgets.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKWidgets.dll
      CTKDICOMWidgets.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKDICOMWidgets.dll
      CTKDICOMWidgetsPlugins.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\designer\Release\CTKDICOMWidgetsPlugins.dll
      PythonQt Wrapping - Generating generated_cpp/org_commontk_CTKDICOMWidgets/org_commontk_CTKDICOMWidgets_init.cpp
      Traceback (most recent call last):
        File "C:\T\SR\CTK\CMake\ctkWrapPythonQt.py", line 252, in <module> ctk_wrap_pythonqt(options.target, options.namespace, options.output_dir, args, options.extra_verbose)
        File "C:\T\SR\CTK\CMake\ctkWrapPythonQt.py", line 93, in ctk_wrap_pythonqtcontent = f.read()
      UnicodeDecodeError: 'cp949' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: Custom build for 
'C:\T\SR\CTK-build\CTK-build\CMakeFiles\84d21e351f9783d195f938f6a6844a08\org_commontk_CTKDICOMWidgets_init.cpp.rule;
C:\T\SR\CTK-build\CTK-build\CMakeFiles\84d21e351f9783d195f938f6a6844a08\moc_org_commontk_CTKDICOMWidgets.cpp.rule;
C:\T\SR\CTK-build\CTK-build\CMakeFiles\1899b50f5d8953e3a01d207c6d8dd4ae\moc_ctkDICOMWidgetsPythonQtDecorators.cpp.rule' exited with code 1. 
[C:\T\SR\CTK-build\CTK-build\Libs\DICOM\Widgets\CTKDICOMWidgetsPythonQt.vcxproj] [C:\T\SR\CTK-build\CTK.vcxproj] [C:\T\SR\CTK.vcxproj]
         Creating library C:/T/SR/CTK-build/CTK-build/bin/Release/CTKImageProcessingITKCore.lib 
         and object C:/T/SR/CTK-build/CTK-build/bin/Release/CTKImageProcessingITKCore.exp
      CTKImageProcessingITKCore.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKImageProcessingITKCore.dll
         Creating library C:/T/SR/CTK-build/CTK-build/bin/Release/CTKImageProcessingITKCorePythonQt.lib 
         and object C:/T/SR/CTK-build/CTK-build/bin/Release/CTKImageProcessingITKCorePythonQt.exp
      CTKImageProcessingITKCorePythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKImageProcessingITKCorePythonQt.pyd
      CTKVisualizationVTKCore.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKVisualizationVTKCore.dll
      CTKVisualizationVTKWidgets.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKVisualizationVTKWidgets.dll
      CTKQtTesting.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKQtTesting.dll
      CTKQtTestingPythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKQtTestingPythonQt.pyd
      CTKScriptingPythonCore.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKScriptingPythonCore.dll
      CTKScriptingPythonWidgets.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKScriptingPythonWidgets.dll
      CTKScriptingPythonWidgetsPlugins.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\designer\Release\CTKScriptingPythonWidgetsPlugins.dll
      CTKScriptingPythonWidgetsPythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKScriptingPythonWidgetsPythonQt.pyd
      CTKVisualizationVTKCorePythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKVisualizationVTKCorePythonQt.pyd
      CTKVisualizationVTKWidgetsPlugins.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\designer\Release\CTKVisualizationVTKWidgetsPlugins.dll
      CTKVisualizationVTKWidgetsPythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKVisualizationVTKWidgetsPythonQt.pyd
      CTKWidgetsPlugins.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\designer\Release\CTKWidgetsPlugins.dll
      CTKWidgetsPythonQt.vcxproj -> C:\T\SR\CTK-build\CTK-build\bin\Release\CTKWidgetsPythonQt.pyd

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5)
: error MSB8066: Custom build for '
C:\T\SR\CTK-build\CMakeFiles\bdeadf76b2a226097eea371c088ff1f3\CTK-configure.rule;
C:\T\SR\CTK-build\CMakeFiles\bdeadf76b2a226097eea371c088ff1f3\CTK-build.rule;
C:\T\SR\CTK-build\CMakeFiles\bdeadf76b2a226097eea371c088ff1f3\CTK-forceconfigure.rule;
C:\T\SR\CTK-build\CMakeFiles\bdeadf76b2a226097eea371c088ff1f3\CTK-install.rule;
C:\T\SR\CTK-build\CMakeFiles\d54a1a094e9ab1ece38bbab3c56288d5\CTK-complete.rule;
C:\T\SR\CTK-build\CMakeFiles\718f3319bb339f95dc70ff401d4b915e\CTK.rule;
C:\T\SR\CTK\CMakeLists.txt' exited with code 1. [C:\T\SR\CTK-build\CTK.vcxproj] [C:\T\SR\CTK.vcxproj]

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5)
: error MSB8066: Custom build for '
C:\T\SR\CMakeFiles\d9658749475c3d792303812dee9bf5c3\CTK-update.rule;
C:\T\SR\CMakeFiles\d9658749475c3d792303812dee9bf5c3\CTK-patch.rule;
C:\T\SR\CMakeFiles\d9658749475c3d792303812dee9bf5c3\CTK-configure.rule;
C:\T\SR\CMakeFiles\d9658749475c3d792303812dee9bf5c3\CTK-build.rule;
C:\T\SR\CMakeFiles\d9658749475c3d792303812dee9bf5c3\CTK-install.rule;
C:\T\SR\CMakeFiles\978258281182d3531409934d713d4cd3\CTK-complete.rule;
C:\T\SR\CMakeFiles\3f47221565dc58dedb5fc6659d43ce89\CTK.rule' exited with code 1. [C:\T\SR\CTK.vcxproj]

It seems like the issue might be related to cp949 Unicode encoding problems on generated cpp file.

I haven’t made any changes to the code; I simply cloned the main branch from the Slicer Git repository and followed the build instructions, but this error occurred. I’m wondering if there is a solution to this issue.

Thank you.

Good catch! This is due to an unlucky coincidence of some recently added CTK files containing a BOM, recently modified Python wrapping code not being robust enough for different encodings, and you using a computer that has system code page set to Korean (cp949). If you change your system code page or any of the two other issues are fixed then you’ll be able to build successfully.

@jcfr, please have a look at:

@Davide_Punzo, could you please fix these files (and maybe disable automatic adding of BOM in your text editor):

2 Likes

Sure! Tomorrow morning I will open a PR!

1 Like

Done in COMP: Remove UTF-8 BOM from source files by Punzo · Pull Request #1215 · commontk/CTK · GitHub

1 Like

After changing the system locale to UTF-8 Beta in Windows and rebuilding the project, it succeeded.
By going into the Control Panel’s system locale settings and selecting ‘Beta: Use Unicode UTF-8 for worldwide language support,’ I was able to solve this issue.

Thank you!

1 Like