How to set the runtime path (-rpath) of an executable with gcc under Mac OSX?

后端 未结 1 1021
庸人自扰
庸人自扰 2020-11-28 04:08

I want to set under Mac OSX the runtime path of an executable (for the linker) at compile time, such that shared libraries at non-standard locations are found by the dynamic

相关标签:
1条回答
  • 2020-11-28 04:36

    Found by experimentation, and inspecting the command lines generated by Xcode for a reference rpath demo project by Dave Driblin:

    otool -L shows you the install name of the linked libraries. To get @rpath to work, you need to change the install name of the library:

    $ gcc -dynamiclib blah.o -install_name @rpath/t/libblah.dylib -o libblah.dylib
    $ mkdir t ; mv libblah.dylib t/
    $ gcc main.c -lblah -L`pwd`/t -Xlinker -rpath -Xlinker `pwd`
    
    0 讨论(0)
提交回复
热议问题