AcademySoftwareFoundation / AcademySoftwareFoundation/OpenTimelineIO
Python `_otio` extension module incorrectly links against external `Imath` library
- Dominant language
- C++
- Stars
- 2k
- Forks
- 351
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 1
Description
I'm building OTIO against an external `Imath` distribution (i.e. `OTIO_FIND_IMATH=ON`), and it looks like the `_otio` Python extension module is being linked directly against the `Imath` lib, leading to the following runtime error:
```
> python -c 'import opentimelineio'
Traceback (most recent call last):
File "", line 1, in
File "/luma/dev/ruschn/rez-release/opentimelineio/0.0.cxx17/platform-linux/gcc-9.3.1/python-3.9/python/opentimelineio/__init__.py", line 14, in
from . import (
File "/luma/dev/ruschn/rez-release/opentimelineio/0.0.cxx17/platform-linux/gcc-9.3.1/python-3.9/python/opentimelineio/opentime.py", line 4, in
from . _opentime import ( # noqa
ImportError: libImath-3_1.so.29: cannot open shared object file: No such file or directory
```
Here is the `patchelf` output for the `_otio` library:
```
>>> patchelf --print-needed /luma/dev/ruschn/rez-release/opentimelineio/0.0.cxx17/platform-linux/gcc-9.3.1/python-3.9/python/opentimelineio/_otio.cpython-39-x86_64-linux-gnu.so
libopentimelineio.so
libopentime.so
libImath-3_1.so.29
libstdc++.so.6
libm.so.6
libgcc_s.so.1
libc.so.6
```
If I manually remove the direct dependency on `libImath-3_1.so.29`, the error is resolved:
```
> patchelf --remove-needed libImath-3_1.so.29 /luma/dev/ruschn/rez-release/opentimelineio/0.0.cxx17/platform-linux/gcc-9.3.1/python-3.9/python/opentimelineio/_otio.cpython-39-x86_64-linux-gnu.so
```
Looking at the CMake build configuration, I'm fairly certain this is because `Imath` is included in the public link interface for the `opentimelineio` target (https://github.com/AcademySoftwareFoundation/OpenTimelineIO/blob/main/src/opentimelineio/CMakeLists.txt#L88-L89), and thus becomes a transitive dependency when the `opentimelineio-bindings` target is linked against it.
## To Reproduce
#### Versions
- CentOS 7.9.2009
- GCC 9.3.1 (installed via `devtoolset-9` RPM)
- CMake 3.25.1
- Imath 3.1.9
- Python 3.9.13
#### CMake Arguments
```
cmake \
-D CMAKE_INSTALL_PREFIX=/path/to/install_prefix \
-D CMAKE_EXE_LINKER_FLAGS=-Wl,--enable-new-dtags \
-D CMAKE_SHARED_LINKER_FLAGS=-Wl,--enable-new-dtags \
-D CMAKE_CXX_STANDARD=17 \
-D CMAKE_CXX_EXTENSIONS=OFF \
-D CMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" \
-D OTIO_PYTHON_INSTALL=ON \
-D OTIO_DEPENDENCIES_INSTALL=OFF \
-D OTIO_FIND_IMATH=ON \
/path/to/source_dir
```
Imath is being located via the `CMAKE_PREFIX_PATH` environment variable, which includes the directory containing the `Imath/ImathConfig.cmake` file.
**Additional Note**: It looks like the `opentime` Python extension module may (unnecessarily?) link against `libopentimelineio`. This may warrant a separate issue.
Contributor guide
Research direction
Start in src/opentimelineio/CMakeLists.txt around lines 88-89 and inspect how the opentimelineio-bindings target receives dependencies. Reproduce the external-Imath configuration, inspect the built _otio module's needed libraries, and verify that importing opentimelineio works without a direct Imath dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100