Skip to content

muslinux: Library loaded with ctypes.cdll.LoadLibrary does not load symbols for python binding module #109332

@LecrisUT

Description

@LecrisUT

Bug report

Bug description:

I am not sure if this was intended to work like that in the first place, but the following works on most linux OS (manylinux I suppose), macos and windows:

import ctypes

ctypes.cdll.LoadLibrary(Path(bundled_lib))           
import _python_binding

where the _python_binding module is built with link_libraries to the one in bundled_lib.

Manually setting rpath makes it work, so I don't think it's an issue with the symbols themselves, but some issue with how ctypes.cdll.LoadLibrary and how the python binding module share the symbols. I have tried to set ctypes.DEFAULT_MODE to either ctypes.RTLD_GLOBAL or ctypes.RTLD_LOCAL, but that doesn't seem to change the behaviour.

An example docker container to replicate this issue is:

FROM python:alpine

RUN apk update
RUN apk add musl-dev gcc linux-headers cmake neovim bash
RUN pip install spglib

with the relevant code in spglib.spglib#58:

$ python -c "import spglib"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.11/site-packages/spglib/__init__.py", line 37, in <module>
    from .spglib import (  # noqa: F401
  File "/usr/local/lib/python3.11/site-packages/spglib/spglib.py", line 67, in <module>
    from spglib import _spglib as spg
ImportError: Error loading shared library libsymspg.so.2: No such file or directory (needed by /usr/local/lib/python3.11/site-packages/spglib/_spglib.cpython-311-x86_64-linux-musl.so)

CPython versions tested on:

3.11

Operating systems tested on:

Other

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions