Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of a project with an external c library and python bindings #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Erotemic
Copy link

This is a somewhat MWE of a type of library that I'd like to wrap, but the other examples don't cover.

The basic idea is that there is:

  • A standalone C library that can be built as a shared object
  • A python wrapper library that has a cython code that links to the C library.

As setup this currently is not working. Running:

    # Build, view, install, and test the wheel
    python setup.py bdist_wheel
    unzip -l dist/my_python_package-1.0.0-*.whl

demonstrates the contents of the wheel as is:

Archive:  dist/my_python_package-1.0.0-cp38-cp38-linux_x86_64.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
       74  2021-09-23 20:03   my_python_package/__init__.py
   207080  2021-09-23 20:03   my_python_package/_cython_wrapper.cpython-38-x86_64-linux-gnu.so
    15136  2021-09-23 20:03   my_python_package-1.0.0.data/data/src/cxx/libmy_c_module.so
      181  2021-09-23 20:03   my_python_package-1.0.0.dist-info/METADATA
       97  2021-09-23 20:03   my_python_package-1.0.0.dist-info/WHEEL
       18  2021-09-23 20:03   my_python_package-1.0.0.dist-info/top_level.txt
      661  2021-09-23 20:03   my_python_package-1.0.0.dist-info/RECORD
---------                     -------
   223246                     7 files

And when I install the wheel I get:

(pyenv3.8.6) joncrall@toothbrush:~/code/scikit-build-sample-projects/projects/clib-wrapper$     python -c "import my_python_package"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/joncrall/.pyenv/versions/3.8.6/envs/pyenv3.8.6/lib/python3.8/site-packages/my_python_package/__init__.py", line 1, in <module>
    from ._cython_wrapper import my_cython_func
ImportError: libmy_c_module.so: cannot open shared object file: No such file or directory

I can build this and make it work if I make libmy_c_module a static library instead of a shared one, but I'd like to fixup this example such that it works and demos how to use skbuild for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant