How to link shared libraries in custom path directly without specifying RPATH?

强颜欢笑 提交于 2019-12-24 18:40:29

问题


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.

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: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'

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?

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.

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?


回答1:


Well, first it would be good to see your cmake file, but alas..

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 )


来源:https://stackoverflow.com/questions/45779088/how-to-link-shared-libraries-in-custom-path-directly-without-specifying-rpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!