在QMake中设置RPATH顺序 [英] Setting RPATH order in QMake

查看:1116
本文介绍了在QMake中设置RPATH顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Linux Qt程序.我希望它优先使用可执行文件目录中的(动态)Qt库(如果存在),否则请使用系统的Qt库. RPATH进行救援.

I have a Linux Qt program. I'd like it to preferentially use the (dynamic) Qt libraries in the executable's directory if they exist, otherwise use the system's Qt libs. RPATH to the rescue.

我将此行添加到 qmake 的.pro文件中:

I add this line to the qmake's .pro file:

QMAKE_LFLAGS    += '-Wl,-rpath,\'\$$ORIGIN\''

并使用 readelf 查看生成的可执行文件,我看到:

and looking at the resulting executable with readelf I see:

0x000000000000000f (RPATH)              Library rpath: [$ORIGIN:/usr/local/Trolltech/Qt-5.2.0/lib]
0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/usr/local/Trolltech/Qt-5.2.0/lib]

似乎正确,但 ldd 显示它正在使用系统版本:

Seems right, but ldd shows it's using the system version:

libQt5Core.so.5 => /usr/local/Trolltech/Qt-5.2.0/lib/libQt5Core.so.5 (0x00007f2d2fe09000)

如果我手动编辑qmake生成的Makefile来交换两个rpath的顺序,那么$ ORIGIN出现在/usr/local/...之后,我得到正确的行为:

If I manually edit qmake's resulting Makefile to swap the order of the two rpaths, so $ORIGIN comes after /usr/local/..., I get the right behavior:

0x000000000000000f (RPATH)              Library rpath: [/usr/local/Trolltech/Qt-5.2.0/lib:$ORIGIN]
0x000000000000001d (RUNPATH)            Library runpath: [/usr/local/Trolltech/Qt-5.2.0/lib:$ORIGIN]

libQt5Core.so.5 => ./libQt5Core.so.5 (0x00007fb92aba9000)

我的问题在于 qmake 如何构造最终的LFLAGS变量.我不知道如何使添加的内容($ ORIGIN)放在系统库之后.有什么想法吗?

My problem is with how qmake constructs the final LFLAGS variable. I can't figure out how to make it put my addition ($ORIGIN) after the system library. Any ideas?

推荐答案

您可以在.pro文件中添加以下内容,以强制动态链接程序在Linux的运行时在与Qt应用程序相同的目录中查找:

You can add the following to your .pro file to force the dynamic linker to look in the same directory as your Qt application at runtime in Linux :

unix:{
    # suppress the default RPATH if you wish
    QMAKE_LFLAGS_RPATH=
    # add your own with quoting gyrations to make sure $ORIGIN gets to the command line unexpanded
    QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
}

如果希望它在可执行路径的子目录中查找,则可以使用:

If you want it to look in a subdirectory of the executable path, you can use :

QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/libs\'"

请注意,您的应用程序目录中应具有完全相同名称的.so文件.例如,您应该将libQt5Core.so.5.2.0复制到名称为libQt5Core.so.5的应用程序目录中.现在,ldd显示了应用程序的目录.

Note that you should have the .so files with the exact same name in your application directory. For example you should copy libQt5Core.so.5.2.0 to your application directory with the name libQt5Core.so.5. Now the ldd shows the directory of the application.

在应用程序目录中,您还可以拥有libQt5Core.so.5.2.0及其名称为libQt5Core.so.5的链接.

You can also have libQt5Core.so.5.2.0 and a link to it with the name libQt5Core.so.5 in the application directory.

这篇关于在QMake中设置RPATH顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆