# ITK 5.3.0 / 5.4rc build errors Shared libs / Python Wrappings / ITKVtkGlue / VS 2022 Win11

**URL:** https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327
**Category:** Engineering
**Created:** [December 1, 2023, 12:59pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327 "2023-12-01T12:59:51Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.itk.org/u/Sophonet)
#### Post date: [December 1, 2023, 12:59pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/1 "2023-12-01T12:59:52Z")

</div>

Hi everyone,

unfortunately I cannot build ITK 5.3.0 (after fixing the castxml problem [Errors building CastXML and Python wrapping on Windows - #13 by dzenanz](https://discourse.itk.org/t/errors-building-castxml-and-python-wrapping-on-windows/5775/13)) or 5.4rc1 with python wrappings.

Problems:

- ITKOptimizersv4Python: LNK2005 “public: class itk::LBFGSOptimizerBaseHelperv4 \* \_\_cdecl itk::LBFGSOptimizerBasev4::GetOptimizer(void)” already defined in itkLBFGSOptimizerBasev4Python.obj
- ITKVtkGlueCastXML: Custom build for ‘…[many XML files are referenced]\InsightToolkit-5.3.0\CMakeFiles\c6ae30f76813b67864f23ad496c55eea\ITKVtkGlueCastXML.rule’ exited with code 1. …with follow-up errors.

My relevant CMake flags:

-D BUILD\_SHARED\_LIBS=True -D ITK\_BUILD\_DEFAULT\_MODULES=True -D Module\_ITKVtkGlue=True -D Module\_ITKIOPhilipsREC=True -D ITK\_WRAP\_PYTHON=True -D ITK\_WRAP\_unsigned\_short=True

Indeed I would like to build shared ITK libraries with python wrappers since I am also building other custom python-wrapped libraries also using ITK (and building dlls on top of static libraries is generally a bad idea due to duplication of singletons etc.).

There is an similar issue related to my first problem, [Linking errors with shared libraries with GradientDescentOptimizerv4Template symbols · Issue #2838 · InsightSoftwareConsortium/ITK · GitHub](https://github.com/InsightSoftwareConsortium/ITK/issues/2838), but I guess this one here would require a different fix.

If the two problems above could/shall not be fixed (e.g. shared lib with python wrapping not possible; wrapping of ITKVtkGlue not possible), then it would be great if an understandable error message could be given from CMake while configuring.

Please let me know if I should open one or two issues on github in case my problems are valid.

Thanks,

sophonet

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 4, 2023, 7:47pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/2 "2023-12-04T19:47:36Z")

</div>

Hello @Sophonet ,

> ITKOptimizersv4Python: LNK2005 “public: class itk::LBFGSOptimizerBaseHelperv4 \* \_\_cdecl itk::LBFGSOptimizerBasev4::GetOptimizer(void)” already defined in itkLBFGSOptimizerBasev4Python.obj

Could you please test this patch?

> <https://github.com/InsightSoftwareConsortium/ITK/pull/4361>
>
> LBFGSOptimizerBasev4 uses the LBFGSOptimizerBasev4 in its interface with the Get…Optimizer method. Wrap LBFGSOptimizerBaseHelperv4 before LBFGSOptimizerBasev4 so LBFGSOptimizerBaseHelperv4 wrapper definition is available.

Additional steps may still be required.

> -D Module\_ITKVtkGlue=True

I would recommend using the [pure python itk-vtk interface](https://docs.itk.org/en/latest/learn/python_quick_start.html#itk-and-vtk).

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.itk.org/u/Sophonet)
#### Post date: [December 4, 2023, 10:00pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/3 "2023-12-04T22:00:41Z")

</div>

Hi @matt.mccormick - thanks for the reply!

(1) [multiply defined symbols]: After changing the order in CMakeLists.txt (your patch), the problem still exists, so maybe more steps are required. Any idea?

(2) [ITKVtkGlue] While the pure python interface might work for python, I need ITKVtkGlue on C++ level. One workaround for me would be to disable wrapping ITKVtkGlue for python (but only wrapping that module) if both ITKVtkGlue and Python wrapping are turned on - instead of letting compilation fail due to a tool crash. Is that possible?

Thanks,

sophonet

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 5, 2023, 6:29pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/4 "2023-12-05T18:29:59Z")

</div>

> [@Sophonet](#):
>
> (1) [multiply defined symbols]: After changing the order in CMakeLists.txt (your patch), the problem still exists, so maybe more steps are required. Any idea?

Thanks for testing! Yes, we need to explicitly instantiate and set the export symbol macros accordingly to avoid the implicit instantiation. Another example of this is `TransformBaseTemplate`.

> (2) [ITKVtkGlue] While the pure python interface might work for python, I need ITKVtkGlue on C++ level.

One approach is to build the [ITKVtkGlue remote module](https://github.com/InsightSoftwareConsortium/ITKVtkGlue) separately against the ITK build and see if we can turn off wrapping in its configuration.

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.itk.org/u/Sophonet)
#### Post date: [December 23, 2023, 11:36am UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/5 "2023-12-23T11:36:01Z")

</div>

Hi Matt,

(1) I could fix the problem by simply making itk::LBFGSOptimizerBasev4::GetOptimizer(void) an inline function in .h (removing the implementation from .hxx). Would that be an option?

(2) The external module you have referenced does not compile, I guess that version is not compatible with the latest VTK anymore. I have fixed it on my machine by checking for ITK\_WRAP\_PYTHON in VtkGlue/Wrapping/CMakeLists.txt, see below. Would that be an option? I have not checked if wrapping to other languages (e.g. Java) still works and should be supported though.

If I should create a merge request, I was wondering how to do it on Windows, since the ITK docs mention a shell script for setting up git.

Thanks,

sophonet

```auto
# Python provides native conversion between ITK and VTK
if(ITK_WRAP_PYTHON)
  MESSAGE("Not wrapping ITKVtkGlue for python, since native version is available https://docs.itk.org/en/latest/learn/python_quick_start.html#itk-and-vtk.")
else()
 // existing wrapping code
endif()

```

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [January 10, 2024, 3:25pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/6 "2024-01-10T15:25:19Z")

</div>

Hi Sophonet,

> [@Sophonet](#):
>
> (1) I could fix the problem by simply making itk::LBFGSOptimizerBasev4::GetOptimizer(void) an inline function in .h (removing the implementation from .hxx). Would that be an option?

Unfortunately, inlining is still going to result in duplicate symbols.

> I guess that version is not compatible with the latest VTK anymore

Unfortunately, VTK breaks downstream builds on a regular basis.

> If I should create a merge request, I was wondering how to do it on Windows, since the ITK docs mention a shell script for setting up git.

Hopefully, [our contributing documentation is clear](https://docs.itk.org/en/latest/contributing/index.html). Yes, there is a bash setup script to help setup your repository for development. On Windows, this can be run with the Git Bash shell, which comes by default with the [git install for Windows](https://git-scm.com/). Please let us know if you have any questions or if the documentation can be improved.

> [@Sophonet](#):
>
> I have fixed it on my machine by checking for ITK\_WRAP\_PYTHON in VtkGlue/Wrapping/CMakeLists.txt, see below.

Overall, looks good!, a few tweaks:

`MESSAGE` → `message(STATUS`

`// existing wrapping code` → `return()` ? (could be cleaner, but is untested)

Thanks!

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.itk.org/u/Sophonet)
#### Post date: [January 12, 2024, 2:41pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/7 "2024-01-12T14:41:48Z")

</div>

Hi Matt,

- Thanks for pointing out that the git-for-windows bash obviously could be used (sorry for having asked this). Maybe that remark could be added to the contribution documentation (just to avoid getting the same stupid question again 😃).

- I was following the contribution docs but “git pullall” is not working on my machine (Windows, git-for-windows 2.43.0), even after running the SetupForDevelopment.sh script. Maybe this is also something that could be clarified in the contribution docs?

- Git commit failed on my system locally, since the clang-format executable was not found. Instead, a a remark was printed that a clang-format binary will be downloaded when BUILD\_TESTING is set to True, but I have done this on my system without success, I have neither found a clang-format executable in my build folder nor in the install folder and the git commit error message does not give a hint where to find it. Also (and this is beyond ITK, there is no clang-format binary available from the clang webpage, I could not find any precompiled Windows builds). Maybe the git commit warning message could be improved and/or the clang-format requirement (and install instructions) could be added to the contributing documentation?

With respect to the LBFGSOptimizerBasev4::GetOptimizer(): Thanks you are right. On Windows, the inline decorator tells MSVC not to generate symbols but I have read that there is no guarantee that other compilers do the same. So once I have pushed the VTKGlue wrapping fix, I will try another solution.

Best,

sophonet

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 12, 2024, 3:28pm UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/8 "2024-01-12T15:28:59Z")

</div>

`clang-format` gets built for me, in e.g. `C:\Dev\ITK-py11\ClangFormat-prefix\src\ClangFormat\clang-format.exe`. When making multiple builds of ITK, the configuration sometimes gets confused and points to `clang-format` in the wrong build folder. If this older build is then deleted, you could end up without it. In that case, a fresh build should also build `clang-format`. One pre-compiled version is attached:  
[clang-format.exe](https://discourse.itk.org/uploads/short-url/3iGJTpi0aiTnuaUVAHen3oHGBdH.exe) (2.4 MB)

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.itk.org/u/Sophonet)
#### Post date: [January 13, 2024, 10:35am UTC](https://discourse.itk.org/t/itk-5-3-0-5-4rc-build-errors-shared-libs-python-wrappings-itkvtkglue-vs-2022-win11/6327/9 "2024-01-13T10:35:22Z")

</div>

Finally managed it, thanks. Another suggestion for the contribution docs would be to start with logging in to GitHub and fork ITK in a first step, then clone the fork. The docs page mentions to clone upstream ITK in step 3 (`https://github.com/InsightSoftwareConsortium/ITK`), into which pushing is not allowed.

I hope my fixes will make it into the next release 5.4 (since they are fixes). Thanks!
