0

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?

user3667089
  • 2,996
  • 5
  • 30
  • 56

1 Answers1

0

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 )
  • This is exactly how I use find_library in my cmake file. It's equivalent of adding this path to RPATH as verified by objdump. – user3667089 Aug 20 '17 at 16:21