简体   繁体   中英

Ship Python Extension that required dynamic linking

I am writing ac 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM