How do *.so files work, and where do they go in UNIX?

老子叫甜甜 提交于 2019-12-11 05:03:53

问题


I've recently been "compiling" python scripts into binary form for the purpose of internal distribution. I'm using the utility cx_freeze which, in it's default state, creates a directory with the primary binary executable in it as well as a bunch of binary *.so files. My understanding is that .so files are libraries, and they are obviously necessary to get the executable binary to function, but my question is how can I link stuff together so they don't all have to be in the same directory? Do I have to determine that at "compile time"? Is there a universal path variable that the executables will look in for libraries it might need, or is that path stated somewhere in the executable itself?

Thanks in advance!


回答1:


The shared objects are searched for by the dynamic linker in a number of locations as explained in the dynamic linker's manpage for linux or OSX:

  1. DT_RPATH attribute stored in the binary for ELF files.
  2. LD_LIBRARY_PATH environment variable if the executable isn't set-user-id/set-group-id.
  3. DT_RUNPATH attribute stored in the binary for ELF files.
  4. /etc/ld.so.cache file which serves as library path cache for the dynamic linker.
  5. Finally, the default directories /lib and /usr/lib.


来源:https://stackoverflow.com/questions/9542357/how-do-so-files-work-and-where-do-they-go-in-unix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!