Build Error: LNK1169 when building ITK with RTK Python wrappers on Windows

I am encountering a linker error (LNK1169) while trying to build the ITK Python wrappers for the Reconstruction Toolkit (RTK). The build fails to generate the itk_RTKPython.pyd file. I have tried several common troubleshooting steps, but the issue persists. I would greatly appreciate any guidance.

1. Environment Information

  • Operating System: Windows 11

  • Compiler: Visual Studio 2022 (MSVC)

  • Architecture: x64

  • CMake Version: 4.1.1

  • Python Version: 3.11 (x64)

  • ITK Version: v5.4.3 (built from source)

  • RTK Version: Enabled Module_RTK within ITK, using version v2.7.0

2. Build Steps

I roughly followed this build process:

  1. Used CMake-GUI to configure and generate the ITK solution. I enabled the ITK_WRAP_PYTHON option.

  2. Set CMAKE_INSTALL_PREFIX to C:\Reconstraction\ITK\Bin.

  3. Enabled the following CMake options: BUILD_SHARED_LIBS, ITKReview, ITK_USE_FFTWD, ITK_USE_FFTWF, ITK_USE_SYSTEM_FFTWD, ITK_USE_SYSTEM_FFTWF (and specified the paths to my FFTW installation). I also enabled Module_cudacommon.

  4. Opened the solution in Visual Studio 2022 and attempted to build the ALL_BUILD target in Release mode.
    The build fails with 68 errors, primarily related to LNK1169.

@simon.rit might want to comment.

new error
LNK2005 "public: class std::vector<class itk::Matrix<double,3,4>,class std::allocator<class itk::Matrix<double,3,4> > > const & __cdecl rtk::ProjectionGeometry<3>::GetMatrices(void)const " (?GetMatrices@?$ProjectionGeometry@$02@rtk@@QEBAAEBV?$vector@V?$Matrix@N$02$03@itk@@V?$allocator@V?$Matrix@N$02$03@itk@@@std@@@std@@XZ) 已经在 rtkProjectionGeometryPython.obj 中定义 RTKPython C:\Reconstraction\ITK\Build\Wrapping\Modules\RTK\itkRTK-5.4.lib(itkRTK-5.4.dll) 1 我想在帖子中询问这个错误

Please describe how one can reproduce this “new error”.

  1. Used CMake-GUI to configure and generate the ITK solution. I enabled the ITK_WRAP_PYTHON option.

  2. Set CMAKE_INSTALL_PREFIX to C:\Reconstraction\ITK\Bin.

Enabled the following CMake options: BUILD_SHARED_LIBS, ITKReview, ITK_USE_FFTWD, ITK_USE_FFTWF, ITK_USE_SYSTEM_FFTWD, ITK_USE_SYSTEM_FFTWF (and specified the paths to my FFTW installation). I also enabled Module_cudacommon.

Then, I used VS2022 to build the ALL_BUILD target in Release mode, and the following error occurs,These errors occur simultaneously:

Creating library C:/Reconstraction/ITK/Build/lib/Release/RTKPython.lib and object C:/Reconstraction/ITK/Build/lib/Release/RTKPython.exp
C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\_RTKPython.pyd : fatal error LNK1169: one or more multiply defined symbols found
Build of project “RTKPython.vcxproj” completed – FAILED.   

I want to use the Python version of RTK with CUDA acceleration. I downloaded it using python -m pip install itk-rtk-cuda124, but my tests kept throwing errors, so I tried compiling ITK and RTK instead…

What are the errors? It’s the same code so I doubt that there will be any difference.

(PyCharmMiscProject) PS C:\Users\lianglab\PyCharmMiscProject> python FirstReconstruction.py output.mha geometry.xml
Traceback (most recent call last):
File “C:\Users\lianglab\PyCharmMiscProject\FirstReconstruction.py”, line 11, in
ImageType = itk.Image[itk.F, 3]
^^^^^^^^^
File “C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\support\lazy.py”, line 138, in getattribute
base.itk_load_swig_module(module, namespace)
File “C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\support\base.py”, line 94, in itk_load_swig_module
itk_load_swig_module(dep, namespace)
File “C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\support\base.py”, line 130, in itk_load_swig_module
l_module = loader.load(swig_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\support\base.py”, line 289, in load
l_spec.loader.exec_module(l_module) # pytype: disable=attribute-error
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 940, in exec_module
File “”, line 241, in _call_with_frames_removed
File “C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\support..\ITKPyBasePython.py”, line 63, in
from itk.pyBasePython import *
File “C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk\pyBasePython.py”, line 15, in
from . import _ITKCommonPython
ImportError: cannot import name 'ITKCommonPython’ from ‘itk’ (C:\Reconstraction\ITK\Build\Wrapping\Generators\Python\itk_init.py)

This is the result of running the First Reconstruction example from RTK.

It seems to have trouble loading the package which might be due to missing libraries. Since you’re using the Cuda package, can you try adding the two lines in CudaFirstReconstruction.py before line 11?

if sys.platform == "win32":
    os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "bin"))

Have you tried the Cuda example?

1 Like