# vtk wheel missing lib\* libraries, missing flag?

**URL:** https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538
**Category:** Support
**Created:** [May 20, 2022, 7:45pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538 "2022-05-20T19:45:55Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![orbisvicis](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/ebca7d/32.png) [@orbisvicis](https://discourse.vtk.org/u/orbisvicis)
#### Post date: [May 20, 2022, 7:45pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/1 "2022-05-20T19:45:55Z")

</div>

A VTK Cygwin build wrapping Python, after patching, produces the following output:

- export libraries: `build/bin/cyg*.dll`
- import libraries: `build/build/lib.cygwin-3.3.4-x86_64-3.8/vtkmodules/lib*.dll.a`
- python libraries: `build/vtkmodules/*.cpython-38-x86_64-cygwin.dll`

The wheel builder then copies the Python modules (`*.py`) and extension modules (`*.dll`) from the Python library directory (`build/vtkmodules/`) to a new directory:

- python wheel directory: `build/build/lib.cygwin-3.3.4-x86_64-cpython-38/`

Which is then copied to `build/build/bdist.cygwin-3.3.4-x86_64` and zipped. As a result, I am lacking the export and import libraries that normally ship with the wheel. If you download an [official VTK wheel from PyPI](https://pypi.org/project/vtk/) you see that it includes, among other things, `/wheel/{*.py, vtk*cpython*so, libvtk*.so*}`. **This means my wheel is unusable.**

If you inspect the [wheel-linux-python310-x86\_64:build](https://gitlab.kitware.com/vtk/vtk/-/jobs/6911816) build log on GitLab you see two differences:

- The export libraries are packaged with the import libraries in what should be, one my side, `build/build/lib.cygwin-3.3.4-x86_64-3.8/vtkmodules/`
- The wheel builder copies the python libraries to the import library directory rather than the new `*cpython*` python wheel directory.

What flags can I use to build my wheel so I get a wheel like an official wheel without missing files? I looked at the [GitLab CI CMake files](https://gitlab.kitware.com/vtk/vtk/-/tree/master/.gitlab/ci) but nothing stood out.

P.S.

[Here is the patch](https://bpa.st/MG3A) I used to build VTK 9.1 (current `master`) on Cygwin. I built it with the following flags (some required):

`cmake -GNinja -DVTK_WRAP_PYTHON=ON -DVTK_ENABLE_WRAPPING=ON -DVTK_USE_TK=ON -DVTK_WHEEL_BUILD=ON -DCMAKE_BUILD_TYPE=RELEASE -DVTK_IGNORE_CMAKE_CXX11_CHECKS=ON -DCMAKE_CXX_FLAGS="-std=gnu++17 -D_GNU_SOURCE -Wa,-mbig-obj" ..`

Since new users can’t post attachments, for the sake of posterity it would by nice for old users to attach that paste for me.

Thanks,

---

<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: [May 21, 2022, 2:08pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/2 "2022-05-21T14:08:00Z")

</div>

Attachment:  
[vtk-cygwin.patch](https://discourse.vtk.org/uploads/short-url/xwXcmD1c2fCG2co8i8REnd7aBw3.patch) (6.1 KB)

---

<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: [May 21, 2022, 2:14pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/3 "2022-05-21T14:14:43Z")

</div>

> [@orbisvicis](#):
>
> This means my wheel is unusable.

The `.dll.a` files shouldn’t be required in the wheel. We don’t ship `.lib` files in the official wheels. What do you need them for?

Note that Cygwin support is best-effort and generally maintained by contributors as it is not an actively tested nor supported platform.

---

<div class="post-metadata">

### Author: ![orbisvicis](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/ebca7d/32.png) [@orbisvicis](https://discourse.vtk.org/u/orbisvicis)
#### Post date: [May 21, 2022, 3:44pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/4 "2022-05-21T15:44:13Z")

</div>

> Note that Cygwin support is best-effort and generally maintained by contributors as it is not an actively tested nor supported platform.

The final patch below allows VTK to compile on Cygwin and is my best effort at contributing a working Cygwin build system. Some of the changes are hacky, some have already been integrated upstream into the `ThirdParty` libraries, some are great, and some… well, let’s just say I don’t know how the VTK maintainers didn’t notice certain build flag combinations probably wouldn’t compile even on Linux (conflict with `X/X.h`). Also some of the customized `ThirdParty` libraries are in horrible state regarding preprocessor macros, especially `loguru` and `netcdf`, but `loguru` upstream is much better. The patch solves the issues in my first post and fixes DLL loading for the Python VTK modules. VTK takes about a day to compile so as far as I’m concerned it’s finished.

> The `.dll.a` files shouldn’t be required in the wheel. We don’t ship `.lib` files in the official wheels. What do you need them for?

I don’t need the `.dll.a` nor the `.lib` files but I need all the `.dll` files. For example, the official Linux wheel ships with VTK-Python modules such as `vtkIOAsynchronous.cpython-38-x86_64-linux-gnu.so` as well as VTK modules such as `libvtkIOAsynchronous-9.1.so` and `libvtkfreetype-9.1.so`. I would need `vtkIOAsynchronous.cpython-38-x86_64-cygwin.dll` as well as `cygvtkIOAsynchronous.dll` and `cygvtkfreetype.dll`, but I only get `vtkIOAsynchronous.cpython-38-x86_64-cygwin.dll` (and other VTK-Python modules).

[vtk.9.1.cygwin.patch](https://discourse.vtk.org/uploads/short-url/qmfBx5L0EevhRxxga74NgLhxxkD.patch) (9.4 KB)

---

<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: [May 21, 2022, 6:44pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/5 "2022-05-21T18:44:58Z")

</div>

Ah. I would check the `CMake/setup.py.in` file for those globs.

Please submit your patch as [a merge request](https://gitlab.kitware.com/vtk/vtk/-/merge_requests).

---

<div class="post-metadata">

### Author: ![orbisvicis](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/ebca7d/32.png) [@orbisvicis](https://discourse.vtk.org/u/orbisvicis)
#### Post date: [May 23, 2022, 11:30am UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/6 "2022-05-23T11:30:09Z")

</div>

Just found out the black magic used to get Cygwin to load the VTK DLL dependencies prevents Python from loading most extension modules. This means VTK has to be imported last. Since I can’t figure a workaround, no merge request.

Specifically, changing `SetDefaultDllDirectories` prevents random Cygwin DLLs from loading, but in combination with `AddDllDirectory` is required to load dependencies of VTK DLLs.

---

<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: [May 23, 2022, 2:07pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/7 "2022-05-23T14:07:19Z")

</div>

This sounds like an issue to raise with Python upstream. Personally, the idea behind `os.add_dll_directory` is nice, but I think the cure is worse than the disease in this case (because of the way the platform works).

---

<div class="post-metadata">

### Author: ![orbisvicis](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/ebca7d/32.png) [@orbisvicis](https://discourse.vtk.org/u/orbisvicis)
#### Post date: [May 24, 2022, 12:09am UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/8 "2022-05-24T00:09:35Z")

</div>

It’s actually a Cygwin issue which I’ve [raised with them](https://cygwin.com/pipermail/cygwin/2022-May/251514.html), but does windows even need [`os.add_dll_directory()`](https://docs.python.org/3/library/os.html#os.add_dll_directory)?

> Only the system paths, **the directory containing the DLL or PYD file** , and directories added with [`add_dll_directory()`](https://docs.python.org/3/library/os.html#os.add_dll_directory) are searched for load-time dependencies.

Anyway I’ve managed to work around the Cygwin issue. Can gitlab import merges from github?

[vtk.9.1.cygwin.patch](https://discourse.vtk.org/uploads/short-url/aD3jnodkjwAnwvxtG5YJ8K6dmuF.patch) (12.6 KB)

---

<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: [May 24, 2022, 12:33pm UTC](https://discourse.vtk.org/t/vtk-wheel-missing-lib-libraries-missing-flag/8538/9 "2022-05-24T12:33:29Z")

</div>

> [@orbisvicis](#):
>
> does windows even need [`os.add_dll_directory()`](https://docs.python.org/3/library/os.html#os.add_dll_directory)?

Yes, in general. Wheels are a degenerate case. It’d still be needed in the general case because any wheel wanting to load VTK libraries would need this `os.add_dll_directory()` (unless they provide their own copy which is…dangerous).

> [@orbisvicis](#):
>
> Can gitlab import merges from github?

Not to my knowledge. But to facilitate feedback, please contribute on gitlab directly. You can login using your github account.
