简体   繁体   English

从 Makefile 中的 c 可执行文件中删除硬编码的 rpath

[英]Remove hardcoded rpath from c executable in Makefile

My c++ Application has a single executable and multiple local shared libraries.我的 c++ 应用程序有一个可执行文件和多个本地共享库。 When I build the executable, the linker(LD) sets the executable RPATH to the path of local shared libraries in the compilation environment.当我构建可执行文件时,链接器(LD)将可执行文件 RPATH 设置为编译环境中本地共享库的路径。

The problem is that when I build a RPM of the application and install the RPM on other system, the application executable looks for the local shared libraries on the directory in which they were present in the compilation environment.问题是,当我构建应用程序的 RPM 并在其他系统上安装 RPM 时,应用程序可执行文件会在编译环境中存在的目录中查找本地共享库。

I want my executable to look for local shared libraries on the path on which they are installed by the RPM, rather than the path on which they were present during the time of compilation.我希望我的可执行文件在 RPM 安装它们的路径上查找本地共享库,而不是在编译时它们所在的路径。

I know I can change the RPATH of my executable once I have installed the RPM using utility chrpath.我知道一旦我使用实用程序 chrpath 安装了 RPM,我就可以更改我的可执行文件的 RPATH。 But I want to automate it.但我想自动化它。 What is the preferred way to do it.Whether through LD flag in Makefile, or by executing CHRPATH from the RPM spec file.什么是首选方法?无论是通过 Makefile 中的 LD 标志,还是通过从 RPM 规范文件执行 CHRPATH。 or is there any other better way.或者有没有其他更好的方法。

rpath is a linker flag and is probably set in LDFLAGS. rpath 是一个链接器标志,可能在 LDFLAGS 中设置。 To remove it simply edit the linker flags in your Makefile.要删除它,只需编辑 Makefile 中的链接器标志。 Or if they are passed in to your build environment in an ambiguous way (they are set before calling make and you are not sure where) you can simply overwrite them:或者,如果它们以模棱两可的方式传递到您的构建环境中(它们在调用 make 之前设置并且您不确定在哪里),您可以简单地覆盖它们:

LDFLAGS = -your_linker_flags 

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM