-
Notifications
You must be signed in to change notification settings - Fork 221
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
Bindings for a shared library #11
Comments
Same problem.... Have you found a solution? |
Not really a solution, but there are two possible workarounds: install libParent.so separately as a dependency, or link libParent.so statically into libBindings.so. |
Nop, this link to the build folder .so |
For a library that is built strictly to support the Python bindings, I decided the most appropriate solution was to build it as a static library and link it into the Python module shared object. E.g.
If you want to install both the supporting library and the Python module as shared objects, the RPATH is harder to manage across different OSes, but what works for me is something like the following: set_target_properties(pymodule PROPERTIES SKIP_BUILD_RPATH FALSE)
In this case the installed paths mirror the build paths. If that is not feasible, then you probably want to separate the libraries into separate projects, build and install one, then build the python module against the installed library. |
Help me!!! If call functions in alprstream.so, These errors occur. Traceback (most recent call last): |
^^^ |
No, your python module (which is just a shared library with an entry point) can depend on shared libraries at runtime just like any other shared library. Such dependencies will just complicate your install, since you have to ship & find them, too (e.g. via package managers). |
@leimao: Like @ax3l says, if you don't have to build a separate shared library, it is easier to avoid it. Not only does it complicate the install, but it also means you have to make sure that RPATH gets set right (or use LD_LIBRARY_PATH), which was the gist of the original issue. But note that a static library can only be linked into a shared library (the Python module) if the static library is compiled with POSITION_INDEPENDENT_CODE, which may not be available in some architectures. |
The PIC thing is indeed required for building/linking a static lib, however, you should not need to muck around with RPATH, LD_LIBRARY_PATH, etc. If you are building python bindings for an external lib, then you should be using |
Shared libraries are localted under site-packages which is not usually in LD_LIBRARY_PATH. Thus, this commit makes internal `xtal_tdzdd` as static library and position independent. See pybind/cmake_example#11 (comment)
Seems that using the target shared object that include pybind as-is, at the same folder as the dependent one, with prefix "lib" at its name, makes it to become visible without adding any search path info. anywhere (credit to Evgeniy Foox) |
If I am wrapping a shared library (e.g.
libParent.so
), and generate python bindings (e.g.libBindings.so
),setup.py
will install bothlibBindings.so
(correctly) andlibParent.so
(incorrectly) to python's.../dist-packages/
..../dist-packages/
directory is not usually in$LD_LIBRARY_PATH
, so the loader does not seelibParent.so
and I get an error like this:Contents of
Bindings/CMakeLists.txt
look like this:Is there an elegant way to solve this?
The text was updated successfully, but these errors were encountered: