Static Linking or Dynamically Looking for Python Libraries
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Sorry if I'm wrong about this. I've looked at the documentation and I couldn't find a solution. Someone more familiar with the internals of the library might have a stupidly simple answer to that.
I made a C++ application that depends on pybind11 and it works perfectly. But because pybind11 is linking dynamically to libpython3.8.dylib and it seems like looking for libpython3.8.dylib is delegated to CMake, other users have not been able to use my application, because they almost always get an error of this kind:
dyld: Library not loaded: @rpath/libpython3.8.dylib
They almost always have a slightly different version of this library and pybind11 can't find it.
Is there an option in CMake to link statically to libpython3.8.a or an alternative for looking for @rpath/libpython3.8.dylib that is not hard-coded, so the application can be distributed?
I've been adding pybind11 with the cmake add_subdirectory command. And it seems like the main options here are:
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
Is there a solution to this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names CMake add_subdirectory and the PYBIND11_INSTALL, PYBIND11_TEST, and PYBIND11_NOPYTHON options; begin by tracing pybind11's CMake configuration and Python library discovery. Determine whether static linking or relocatable distribution is supported, and define how the result would be verified for a macOS consumer application.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- build-system, desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100