# Cannot wrapping module for python

**URL:** https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281
**Category:** Support
**Tags:** python
**Created:** [February 19, 2025, 11:34am UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281 "2025-02-19T11:34:36Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Mat\_F](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mat_f/32/9807_2.png) [@Mat\_F](https://discourse.vtk.org/u/Mat_F)
#### Post date: [February 19, 2025, 11:34am UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/1 "2025-02-19T11:34:36Z")

</div>

Hi all,  
as I early mentioned on title, I’m trouble with the wrapping of custom classes to python. I had search for long time but i didnt found nothing to solve my case.  
Below all steps to reproduce the error:

`git clone --depth 1 --branch v9.4.1 https://gitlab.kitware.com/vtk/vtk.git`

`cd vtk/Examples/Modules/Wrapping`

`python -m venv venv`

`source venv/bin/activate`

`pip install vtk`

`mkdir build && cd build`

```auto
cmake .. \
    -DVTK_DIR=../venv/lib/python3.12/site-packages/vtkmodules/cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DVTK_WRAP_PYTHON=ON

```

`cmake --build .`

then I’ve copied “wrapping” folder from build/lib/python3/dist-packages/wrapping to venv/lib/python3.12/site-packages/  
and copied “libvtkWrappable.so” from build/lib/ to venv/lib

after that

```auto
python
Python 3.12.7 (main, Feb 12 2025, 12:16:38) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wrapping.vtkWrappable
Errore di segmentazione (core dump creato)

```

I can’t say what goes wrong and I dont have found a solid guide to build correctly this wrapper.  
The main goal is to subclass the vtkLegendScaleActor (in c++) in order to import on a python script beacuse I need to modify the logic on BuildRepresentation method, but for now I’m focusing to get a example build.  
Can you help me to solve this? Thanks in advance

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 3, 2025, 11:09pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/3 "2025-03-03T23:09:39Z")

</div>

> [@Mat\_F](#):
>
> then I’ve copied “wrapping” folder from build/lib/python3/dist-packages/wrapping to venv/lib/python3.12/site-packages/

Your VTK build is probably subtly incompatible with the wheel VTK. You might have better luck grabbing the relevant wheel SDK bundle (named `vtk-wheel-sdk-*` on [this page](https://vtk.org/download/)) and building projects against it.

---

<div class="post-metadata">

### Author: ![Mat\_F](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mat_f/32/9807_2.png) [@Mat\_F](https://discourse.vtk.org/u/Mat_F)
#### Post date: [March 20, 2025, 11:04am UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/4 "2025-03-20T11:04:29Z")

</div>

Hi Ben, thanks for your reply.  
Finally I have build the wrapper and works when imported on a custom venv. Now I’m facing another problem that concerns vtkCommonCore compatibiliy. My lib links to my system’s vtk lib, and I think need to build wrapper linking to venv vtk libs.  
The error:

```python
    from customodules.renderingAnnotation import LegendScaleActor
ImportError: Initialization failed for renderingAnnotation, not compatible with vtkmodules.vtkCommonCore

```

This appens when the vtk lib goes installed trough pip, but when I copy the entire vtk lib generated on my system (using the same version 9.4.1) this problem goes away.  
In any case i need to use pip’s vtk lib.  
Any suggestions?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 20, 2025, 12:02pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/5 "2025-03-20T12:02:15Z")

</div>

> [@Mat\_F](#):
>
> My lib links to my system’s vtk lib, and I think need to build wrapper linking to venv vtk libs.

Yes, you do. There are SDK bundles to be compatible with the wheels on the page I linked to [here](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/3).

---

<div class="post-metadata">

### Author: ![Mat\_F](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mat_f/32/9807_2.png) [@Mat\_F](https://discourse.vtk.org/u/Mat_F)
#### Post date: [March 20, 2025, 1:41pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/6 "2025-03-20T13:41:23Z")

</div>

I’m trying to build it with your advice, but the lib points to system’s lib

```bash
ldd librenderingAnnotation.so
        linux-vdso.so.1 (0x00007fff0d5c1000)
        libvtkRenderingAnnotation-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkRenderingAnnotation-9.4.so.1 (0x000070fe2a751000)
        libvtkRenderingFreeType-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkRenderingFreeType-9.4.so.1 (0x000070fe2a6ab000)
        libvtkRenderingCore-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkRenderingCore-9.4.so.1 (0x000070fe2a400000)
        libvtkCommonCore-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonCore-9.4.so.1 (0x000070fe28a00000)
        libvtksys-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtksys-9.4.so.1 (0x000070fe2a3a8000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x000070fe28600000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x000070fe2a34e000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000070fe28200000)
        libvtkFiltersSources-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkFiltersSources-9.4.so.1 (0x000070fe2890c000)
        libvtkFiltersGeneral-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkFiltersGeneral-9.4.so.1 (0x000070fe27c00000)
        libvtkFiltersCore-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkFiltersCore-9.4.so.1 (0x000070fe27000000)
        libvtkCommonExecutionModel-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonExecutionModel-9.4.so.1 (0x000070fe284ed000)
        libvtkCommonDataModel-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonDataModel-9.4.so.1 (0x000070fe26800000)
        libvtkCommonTransforms-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonTransforms-9.4.so.1 (0x000070fe288c7000)
        libvtkCommonMath-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonMath-9.4.so.1 (0x000070fe2889d000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000070fe27b17000)
        libvtkfreetype-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkfreetype-9.4.so.1 (0x000070fe28435000)
        libvtkCommonColor-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonColor-9.4.so.1 (0x000070fe2a32d000)
        libvtkCommonComputationalGeometry-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonComputationalGeometry-9.4.so.1 (0x000070fe281ca000)
        libvtkFiltersGeometry-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkFiltersGeometry-9.4.so.1 (0x000070fe26e81000)
        libvtkCommonSystem-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonSystem-9.4.so.1 (0x000070fe28415000)
        libvtkCommonMisc-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkCommonMisc-9.4.so.1 (0x000070fe26200000)
        libvtktoken-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtktoken-9.4.so.1 (0x000070fe28881000)
        libvtkdoubleconversion-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkdoubleconversion-9.4.so.1 (0x000070fe27b05000)
        libvtkloguru-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkloguru-9.4.so.1 (0x000070fe27af1000)
        /lib64/ld-linux-x86-64.so.2 (0x000070fe2a897000)
        libvtkFiltersVerdict-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkFiltersVerdict-9.4.so.1 (0x000070fe26e42000)
        libvtkfmt-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkfmt-9.4.so.1 (0x000070fe27ac9000)
        libvtkFiltersReduction-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkFiltersReduction-9.4.so.1 (0x000070fe26621000)
        libvtkpugixml-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkpugixml-9.4.so.1 (0x000070fe261c3000)
        libvtkkissfft-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkkissfft-9.4.so.1 (0x000070fe281c3000)
        libvtkzlib-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkzlib-9.4.so.1 (0x000070fe26e24000)
        libvtkverdict-9.4.so.1 => /usr/local/vtk-9.4.1/lib/libvtkverdict-9.4.so.1 (0x000070fe2618f000)

```

Can i ask you how to build correctly, step by step? Probably I’m missing somethiing but I don’t know what.  
Thanks in advance

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 20, 2025, 1:46pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/7 "2025-03-20T13:46:35Z")

</div>

@jcfr or @banesullivan Do you have experience using these SDKs?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 20, 2025, 5:38pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/8 "2025-03-20T17:38:21Z")

</div>

I think this can be fixed by setting `INSTALL_RPATH` to something relative to `$ORIGIN` when you build your project, e.g. `$ORIGIN/../vtkmodules`. I’m foggy on the details because I haven’t worked with rpath-related settings recently.

---

<div class="post-metadata">

### Author: ![Mat\_F](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mat_f/32/9807_2.png) [@Mat\_F](https://discourse.vtk.org/u/Mat_F)
#### Post date: [March 21, 2025, 10:36am UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/9 "2025-03-21T10:36:28Z")

</div>

Hi all,  
I want to share some updates.  
After serveral attemps I managed to build the lib with SDK download from [here](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/3) as suggested by Ben.  
The SDK appears incomplete because can’t resolve symbols like “vtkObject::GetObjectDescription()”

```python
Python 3.12.7 (main, Feb 12 2025, 12:16:38) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mymodules import renderingAnnotation
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/matteo/test/vtk_modules/Custom/venv/lib/python3.12/site-packages/mymodules/librenderingAnnotation.so: undefined symbol: _ZNK9vtkObject20GetObjectDescriptionB5cxx11Ev

```

What I’m missing now?  
The SDK is [vtk-wheel-sdk-9.4.1-cp312-cp312-manylinux\_2\_17\_x86\_64.manylinux2014\_x86\_64.tar.xz](https://vtk.org/files/release/9.4/vtk-wheel-sdk-9.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz)

In the other way, with full vtk built, this problem goes away, but cannot “communicate” with vtkCommonCore of pip’s version.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 21, 2025, 1:29pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/10 "2025-03-21T13:29:21Z")

</div>

The missing symbol seems to be a mangling issue. The symbol provided by the SDK’s `libvtkCommonCore.so` is:

```
_ZNK9vtkObject20GetObjectDescriptionEv

```

But the symbol your build wants is

```
_ZNK9vtkObject20GetObjectDescriptionB5cxx11Ev

```

So the build is adding `B5cxx11` to the symbol. I’m not familiar with “Bnxxxx” mangling, but you can try adding the following to your CMakeLists.txt, which will match with the C++ std version used by the SDK:

```
set(CMAKE_CXX_STANDARD 11)

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 21, 2025, 2:13pm UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/11 "2025-03-21T14:13:39Z")

</div>

Follow-up: `B5cxx11` is `abi:cxx11`, which is described here:  
[https://gcc.gnu.org/onlinedocs/libstdc++/manual/using\_dual\_abi.html](https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html)  
According to that, `abi:cxx11` can be removed from symbols by adding this (e.g. to CMakeLists.txt):

```
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

```

The symbol for the `GetObjectDescription()` method is afflicted because it returns a string, and the ABI for strings changed between c++98 and c++11.

---

<div class="post-metadata">

### Author: ![Mat\_F](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mat_f/32/9807_2.png) [@Mat\_F](https://discourse.vtk.org/u/Mat_F)
#### Post date: [March 24, 2025, 9:28am UTC](https://discourse.vtk.org/t/cannot-wrapping-module-for-python/15281/12 "2025-03-24T09:28:27Z")

</div>

Hi all!  
Friday on late I’ve resolved and I promised to myself to reply here today.  
But I see only today that David has answer with the same solution that I’ve discovered too.

So thanks for the support and for answering. Probably that isn’t a best practice but for now is the only way that permits me to obtain an external library based on vtk wheel.

In any case if you got a better way to do that i’ll appreciate to know it.  
For now thanks to all
