How to get RPATH with $ORIGIN to work on Code::Blocks GCC?

前端 未结 3 975
你的背包
你的背包 2020-12-25 14:24

I\'m trying to link an RPATH containing the special string $ORIGIN into an executable built using GCC with the Code::Blocks IDE. I\'ve specified

-Wl,-R$ORIGI         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 15:24

    If your executable is being built by a huge complex script environment not created by you, and you don't want to delve into with that, trying running with setenv LD_RUN_PATH='$ORIGIN/../lib'; if that doesn't work, a pragmatic approach is to create a wrapper for ld:

    #!/bin/sh
    exec /usr/bin/ld -R '$ORIGIN/../lib' "$@"
    

    ... then do the build with that stub on the path. In practice it may be called to build .so files, or other executables, so you may need to make this a more complex script that decides whether to insert the RPATH. OR, run build without this, and with, and cherry pick.

    (here "/usr/bin/ld" is the ld that would normally have been run, which may be somewhere else. gcc may not pick up ld from the path, see gcc environment variables to override that. Mileage may vary. Single use only. Not warranted to be less awful than any other approach).

提交回复
热议问题