Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

building lib with pybind11 linking other shared lib

My project reply on a SO file which I will make it by cmake installing under my project folder.And it works files when I run python setup.py install

But I install it by pip, because pip will copy the project into a tmpfile,It will be removed after installed and the SO file also be removed. Hence, when I import my project, it fails for not finding the SO file.

Of course, I can install the SO file to /usr/local/lib, but I don't want to

Anyone has idea to solve it?

like image 387
binbin Avatar asked Nov 01 '25 05:11

binbin


2 Answers

You need to make your shared library discoverable at run time. Same rules applies as for regular C++ executable.

There are several options here (list might be incomplete):

  • Place shared library along with other shared libraries (e.g. /usr/lib/)
  • Add custom conf with path to shared library to /etc/ld.so.conf.d/my_lib.conf
  • Set LD_LIBRARY_PATH before calling python interpreter
  • Use LD_PRELOAD to run python interpreter
  • Set path to shared library as RPATH attribute of pybind11 module.

I personally use the latter option: it allows me to use virtualenv freely

like image 67
Sergei Avatar answered Nov 02 '25 19:11

Sergei


You can also take a look at auditwheel if you have a wheel package.

auditwheel repair: copies these external shared libraries into the wheel itself, and automatically modifies the appropriate RPATH entries such that these libraries will be picked up at runtime. This accomplishes a similar result as if the libraries had been statically linked without requiring changes to the build system. Packagers are advised that bundling, like static linking, may implicate copyright concerns.

like image 29
Zouzias Avatar answered Nov 02 '25 19:11

Zouzias