Shared library dependencies with distutils

后端 未结 2 896
一生所求
一生所求 2020-12-13 14:52

I\'m a newbie to distutils and I have a problem that really has me stuck. I am compiling a package that requires an extension, so I make the extension thus:

         


        
2条回答
  •  心在旅途
    2020-12-13 15:47

    You can have the linker store paths to search in the output binary so LD_LIBRARY_PATH isn't necessary. Some examples:

    # Will link fine but at run-time LD_LIBRARY_PATH would be required
    gcc -o blah blah.o -lpcap -L/opt/csw/lib
    
    # Without LD_LIBRARY_PATH=/opt/csw/lib it will fail to link, but
    # it wouldn't be needed at run-time
    gcc -o blah blah.o -lpcap -Wl,-R/opt/csw/lib
    
    # LD_LIBRARY_PATH not needed at link or run-time
    gcc -o blah blah.o -lpcap -Wl,-{L,R}/opt/csw/lib
    
    # This makes it possible to use relative paths; run `readelf -d binary_name`
    # and you'll see '$ORIGIN/../lib/' in RPATH.  This plus `-zorigin` make it look
    # relative to the binary for libraries at run-time
    gcc -o blah blah.o -lsomelib -L/whatever/path/floats/your/boat -Wl,-R'$ORIGIN/../lib/' -Wl,-zorigin
    

    .. where:

    • paths given with -L are used at link-time
    • paths given with -R are used at run-time

提交回复
热议问题