mexopencv
mexopencv copied to clipboard
Invalid MEX-file
Hi all,
I am experiencing invalid MEX-file issue, which I think it may be a little different from the errors that other people are experiencing, so I'm raising an issue.
To explain what I've done so far:
I've just followed the Linux installation guide to install mexopencv on MATLAB 2018b on Ubuntu 16.04LTS.
I noticed that there was the GCC version mismatch during the build, but the mex-ing operation seemed to go successfully.
After setting the path, I tried the two commands shown at the installation guide, which are:
- cv.getBuildInformation()
- UnitTest('ContributeModules',true) (After adding the test folder in the Matlab path)
This is what the cv.getBuildInformation()
shows:
General configuration for OpenCV 3.4.0 =====================================
Version control: unknown
Platform:
Timestamp: 2018-03-22T14:46:28Z
Host: Linux 4.4.0-0.bpo.tmw1-amd64 x86_64
CMake: 3.4.3
CMake generator: Unix Makefiles
CMake build tool: /mathworks/hub/3rdparty/internal/2106168/glnxa64/gmake/bin/gmake
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2
requested: SSE4_1 SSE4_2 AVX FP16 AVX2
SSE4_1 (3 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (9 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
C/C++:
Built as dynamic libs?: YES
C++11: YES
C++ Compiler: /mathworks/hub/3rdparty/internal/2501977/glnxa64/gcc-6.3.0/bin/g++ (ver 6.3.0)
C++ flags (Release): -O2 -pipe -pthread -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O2 -pipe -pthread -fPIC -DNDEBUG
C++ flags (Debug): -O2 -pipe -pthread -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O2 -pipe -pthread -fPIC -DDEBUG -D_DEBUG
C Compiler: /mathworks/hub/3rdparty/internal/2501977/glnxa64/gcc-6.3.0/bin/gcc
C flags (Release): -O2 -pipe -pthread -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O2 -pipe -pthread -fPIC -DNDEBUG
C flags (Debug): -O2 -pipe -pthread -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O2 -pipe -pthread -fPIC -DDEBUG -D_DEBUG
Linker flags (Release): -pthread -Wl,--hash-style=both -L/tmp/B3p3/glnxa64/OpenCV/lib
Linker flags (Debug): -pthread -Wl,--hash-style=both -L/tmp/B3p3/glnxa64/OpenCV/lib
ccache: YES
Precompiled headers: NO
Extra dependencies: dl m pthread rt cudart nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/mathworks/devel/bat/B3p3/build/3p/install/3323569/glnxa64/CUDA/lib64
3rdparty dependencies:
OpenCV modules:
To be built: calib3d core cudaarithm cudabgsegm cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev dnn features2d flann imgproc ml objdetect photo python2 python_bindings_generator shape stitching superres video videostab
Disabled: highgui imgcodecs js videoio world
Disabled by dependency: cudacodec
Unavailable: java python3 ts viz
Applications: apps
Documentation: YES (/usr/bin/doxygen 1.8.8)
Non-free algorithms: NO
GUI:
VTK support: NO
Media I/O:
ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
Video I/O:
gPhoto2: NO
Parallel framework: pthreads
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2017.0.3 [2017.0.3]
at: /tmp/B3p3/glnxa64/OpenCV/3rdparty/ippicv/ippicv_lnx
Intel IPP IW: sources (2017.0.3)
at: /tmp/B3p3/glnxa64/OpenCV/3rdparty/ippicv/ippiw_lnx
Lapack: NO
Eigen: NO
Custom HAL: NO
NVIDIA CUDA: YES (ver 9.1, CUFFT CUBLAS)
NVIDIA GPU arch:
NVIDIA PTX archs:
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.9)
Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.9)
numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
packages path: lib/python2.7/dist-packages
Python (for build): /usr/bin/python2.7
Java:
ant: NO
JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include
Java wrappers: NO
Java tests: NO
Matlab: NO
Install to: /mathworks/devel/bat/B3p3/build/3p/install/3323569/glnxa64/OpenCV
And this is what I get after the UnitTest('ContriModules',true)
>> UnitTest('ContribModules',true)
Error using cv.imread
Invalid default value for property 'im' in class 'TestImwrite':
**Invalid MEX-file '/home/changh95/cv/mexopencv/+cv/imread.mexa64': /lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not
found (required by /home/changh95/anaconda3/lib/libpng16.so.16).**
Error in UnitTest>testsuite_fromClass (line 340)
mc = meta.class.fromName(klass);
Error in UnitTest>@(c)testsuite_fromClass(c,opts) (line 230)
tests = cellfun(@(c) testsuite_fromClass(c, opts), names, ...
Error in UnitTest>testsuite_fromFolder (line 230)
tests = cellfun(@(c) testsuite_fromClass(c, opts), names, ...
Error in UnitTest>@(d)testsuite_fromFolder(d,opts) (line 73)
tests = cellfun(@(d) testsuite_fromFolder(d, opts), opts.TestDirs, ...
Error in UnitTest (line 73)
tests = cellfun(@(d) testsuite_fromFolder(d, opts), opts.TestDirs, ...
As you see, there seems to be a library clash between the essential libraries for mexopencv and the libraries under anaconda3 (which I installed for pytorch purpose).
If any of you guys know how to resolve this library issues, please share your solutions and I'll greatly appreciate your support :)
Do you have the Computer Vision System Toolbox?
>> ver vision
>> ls /usr/local/MATLAB/R2018b/bin/glnxa64/libopencv*
The output from getBuildInformation
indicates that the wrong opencv is being loaded at runtime (v3.4.0 libs that ship with CVST toolbox, not the v3.4.1 libs you would have built from source if you followed the wiki installation guide).
To see the conflicting libraries, run ldd
both inside MATLAB and outside in a terminal:
% MATLAB
>> !ldd /home/changh95/cv/mexopencv/+cv/imread.mexa64
# Terminal
$ ldd /home/changh95/cv/mexopencv/+cv/imread.mexa64
You'll need to preload the libs as needed, as explained in the troubleshooting section:
$ LD_PRELOAD=/usr/local/lib/libopencv_core.so.3.4:[...etc...] matlab
As alternative, you could simply avoid the conflict with CVST libs by moving/renaming them temporarily before starting matlab to run mexopencv.
A third way, which I haven't tested myself, is to use RPATH when building the mex-files, that way the mex-files are hardcoded to look for the locally-installed opencv libs first. You would build mexopencv as following:
$ LDFLAGS=-Wl,-rpath,/usr/local/lib make all contrib
FYI here's a similar previous discussion: https://github.com/kyamagu/mexopencv/issues/352#issuecomment-321618725