How to set RPATH and RUNPATH with GCC/LD?

前端 未结 2 528
栀梦
栀梦 2020-12-05 21:15

I recently encountered this problem after an upgrade of the system: using the GCC -Wl,-rpath= option works differently than before.

I used it to set the

2条回答
  •  无人及你
    2020-12-05 22:03

    Is there a way to force the old behavior?

    Yes. You can use this option -Wl,--disable-new-dtags to tell the new linker to use the old behavior, i.e. RPATH.

    Is it possible to tell the old version of linker to produce the new output (i.e. RUNPATH instead of RPATH)?

    Yes. Use -Wl,--enable-new-dtags to tell the old linker to use the new behavior, i.e. RUNPATH.

    I verified the executable with readelf and these two options seem to control what will be written in the ELF Dynamic section. I think the problem was caused by a change in the defaults for the new version, although, interestingly, the manual page for ld would suggest that it should still be the same:

    --enable-new-dtags
    --disable-new-dtags
    This linker can create the new dynamic tags in ELF. But the older ELF systems may not understand them. If you specify --enable-new-dtags, the new dynamic tags will be created as needed and older dynamic tags will be omitted. If you specify --disable-new-dtags, no new dynamic tags will be created. By default, the new dynamic tags are not created. Note that those options are only available for ELF systems.

提交回复
热议问题