1

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!

gr4nf
  • 29
  • 1
  • 1
  • 2
  • Possible duplicate / closely related question: http://stackoverflow.com/questions/5130654/when-how-does-linux-load-shared-libraries-into-address-space – jogojapan Mar 03 '12 at 01:07

1 Answers1

4

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.
Sep
  • 347
  • 3
  • 13
Adam Zalcman
  • 26,643
  • 4
  • 71
  • 92
  • Okay, so if cx_Freeze gives me a bunch of .so files, I would think I could just throw them in /lib and the linker would be able to find them? But that doesn't work. It seems like I should be able to specify something at compile time pointing it to the shared object files? Thanks for your answer! – gr4nf Mar 06 '12 at 20:13
  • Putting the libraries in /lib should work. You can use ldd command to see which libraries are picked up and from where. I don't know which compiler you're using, but it is highly likely it has the flags you're looking for. Check compiler's documentation. If you're using gcc check out -l and -L. – Adam Zalcman Mar 07 '12 at 09:25