I am writing a c extension (called my_ext
) and I successfully compiled the source code to a .so file. However, my_ext
depends another dynamic library installed by pip. So the link directory looks like <virtual_env>/lib/python3.6/site-packages/foo
. And my link command looks like this g++ -fPIC -L<virtual_env>/lib/python3.6/site-package/foo/ -lfoo ...
and I am able to link successfully. However, my question is that since my link_directory is hard-coded according to path in my laptop. When I package my python package and ship to customer, how will that extension load libfoo.so? I assume it will look for the path hard-coded by me right? In this case, customer might not be able to load libfoo.so. How can I resolve this issue?
Asked
Active
Viewed 77 times
0

Howard Yu
- 171
- 1
- 10
1 Answers
0
However, my question is that since my link_directory is hard-coded according to path in my laptop
It shouldn't be. How did you come to conclusion that it is?
Run readelf -d my_ext.so
, and see if there is a reference to the path on your laptop. If there is (unlikely), update your question with the output from readelf -d
, and a better answer may come.

Employed Russian
- 199,314
- 34
- 295
- 362
-
I figure it out. I just bundled all so file into my wheel package and use RPATH to indicate search path. – Howard Yu Jul 26 '19 at 14:54