Skip to content

How to install a shared C library? #1035

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

Closed
dmitry-kabanov opened this issue Mar 28, 2025 · 3 comments
Closed

How to install a shared C library? #1035

dmitry-kabanov opened this issue Mar 28, 2025 · 3 comments

Comments

@dmitry-kabanov
Copy link

It seems that scikit-build-core defines CMAKE_INSTALL_PREFIX to site-packages, that is, everything is assumed to by either Python files or Python C extensions.

However, I need to install a C library, and I cannot do it somehow, although it should go to /lib/ directly, not to /lib/pythonX.Y/site-packages,
where initial / is the root of a virtual environment.

I am trying to install the library this way:

install(TARGETS oif_dispatch DESTINATION ../..) 

and the library is just not getting installed at all, with the following lines during pip install -v:

  -- Installing: /tmp/tmp2c5eaghh/wheel/platlib/../../liboif_dispatch.so
  -- Set non-toolchain portion of runtime path of "/tmp/tmp2c5eaghh/wheel/platlib/../../liboif_dispatch.so" to ""

So, I cannot find it anywhere in the virtual environment.

Question how to write the install command, so that scikit-build-core installs the actual library? Thank you!

@LecrisUT
Copy link
Collaborator

The destination you are pointing to is outside the wheel directory. The current default you have is ./ is pointing to the lib64/pythonX.Y/site-packages/, so I think you want to install it there? Otherwise you can also use other installation paths like https://scikit-build-core.readthedocs.io/en/latest/guide/cmakelists.html#install-directories.

Note that as indicated in the log, the RPATHs are stripped so depending on how you want to handle it, you might want to install somewhere in your package path or otherwise you would not have a predictable path to construct your INSTALL_RPATH. You could use wheel repair tools like auditwheel to automatically fix the RPATHs, but these would have trouble doing this for pointing to dependencies within the wheel. For that I am considering adding a native wheel repair feature to take the information available during the CMake build #1009. I also want to document some common pitfalls of the dynamic libraries packaging in #1022.

@henryiii
Copy link
Collaborator

henryiii commented Mar 28, 2025

If you want it to go to lib, you can install to ${SKBUILD_DATA_DIR}/lib. However, there are drawbacks to this; if someone installs directly to their system Python, this will be installed into /usr/lib or /lib. On macOS, Homebrew will even start warning about non-homebrew stuff being added to its folders. It's fine if you use a venv, but not everyone does. Most packages prefer to put the libraries inside the site-packages folder, and load them from there, importlib has ways to help find stuff in site-packages. For example, pybind11 puts all of it's headers inside site-packages/pybind11, and only if you install pybind11[global] do you get the /include directory copy.

https://scikit-build-core.readthedocs.io/en/latest/guide/cmakelists.html

@dmitry-kabanov
Copy link
Author

Thank you very much for the explanation!

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

No branches or pull requests

3 participants