如何在不指定RPATH的情况下直接在自定义路径中链接共享库? [英] How to link shared libraries in custom path directly without specifying RPATH?
问题描述
我在Ubuntu 16.04上,并且我需要使用外部库( MCR ).它将所有共享库放在MATLAB/bin/glnxa64/
文件夹中.我只需要libmx.so,但那里的库名称与/usr/lib
中的库名称完全相同,但实际上它们是不同的(因为文件大小不同),例如libtiff.so.5
.
I am on Ubuntu 16.04, and I am required to use an external library (MCR). It puts all of it's shared libraries inside the MATLAB/bin/glnxa64/
folder. I only need the libmx.so in there but there are libraries in there that has the exact same name as the ones in /usr/lib
but they are actually different (because the file size is different), for example libtiff.so.5
.
这成为一个问题,因为当我在CMake中使用find_library
函数将MATLAB/bin/glnxa64/
添加到RPATH中以链接到我的应用程序的libmx.so时,因为我的应用程序还依赖于另一个外部库(OpenCV),在构建时已链接到/usr/lib
中的libtiff.so.5
,当我编译我的应用程序时,它显示出编译错误
This becomes a problem because when I use the find_library
function in CMake to add MATLAB/bin/glnxa64/
into RPATH in order to link to libmx.so for my application, since my application also depends on another external library (OpenCV) that was linked to the libtiff.so.5
in /usr/lib
when it was built, when I compile my application it shows an compilation error of
/usr/lib/libopencv_imgcodecs.so.3.3.0:未定义的引用 `TIFFReadDirectory@LIBTIFF_4.0'
/usr/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
这是因为我的应用程序试图链接到MATLAB/bin/glnxa64/
中的libtiff.so.5
而不是/usr/lib
,因为RPATH的优先级高于默认目录.解决此问题的最佳方法是什么?
It is because my application is trying to link to the libtiff.so.5
in MATLAB/bin/glnxa64/
instead of /usr/lib
because RPATH has a higher priority than the default directories. What is the best way to solve this?
我尝试将MATLAB/bin/glnxa64/
中的libtiff.so.5
重命名为类似libtiff_old.so.5
的名称.这可以解决,但是非常难看.
I tried renaming the libtiff.so.5
in MATLAB/bin/glnxa64/
to something like libtiff_old.so.5
. This solves it but is very ugly.
无论如何,我是否可以更改搜索优先级,以使RPATH遵循默认目录?还是我可以在CMake中做些什么,以便我的应用程序可以直接链接到libmx.so,而不必在RPATH中添加MATLAB/bin/glnxa64/
来弄乱事情?
Is there anyway I can alternate the search priority so RPATH goes after the default directories? Or is there something I can do in CMake so my application can directly link to libmx.so without having to add MATLAB/bin/glnxa64/
into RPATH to mess things up?
推荐答案
嗯,首先很高兴看到您的cmake文件,但是but.
Well, first it would be good to see your cmake file, but alas..
您可以尝试使用它,< ...>是MATLAB安装的基本目录,它可能是/usr/local/或/opt.
You can try using this, the <...> is your base directory for the MATLAB install, which might be /usr/local/ or /opt.
find_library (MATLAB_RUNTIME libmx
PATHS <...>/MATLAB/bin/glnxa64/
NO_DEFAULT_PATH )
这篇关于如何在不指定RPATH的情况下直接在自定义路径中链接共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!