-
Notifications
You must be signed in to change notification settings - Fork 319
Invalid MEX function in MATLAB R2015a Mac OS #250
Comments
@mzahana It's a dependency problem. You probably have multiple versions of otool -L /Users/abdkadma/Dropbox/git/mexopencv/+cv/private/CascadeClassifier_.mexmaci64 If, for any reason, you need to keep old incompatible |
Thanks for the reply. Here is what I get when I run the /Users/abdkadma/Dropbox/git/mexopencv/+cv/private/CascadeClassifier_.mexmaci64:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 20.0.0)
/usr/local/opt/opencv3/lib/libopencv_shape.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_stitching.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_objdetect.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_superres.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_videostab.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_calib3d.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_features2d.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_highgui.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_videoio.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_imgcodecs.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_video.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_photo.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_ml.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_imgproc.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_flann.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/opt/opencv3/lib/libopencv_core.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
@rpath/libmx.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libmex.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
How can I update the Thanks. |
@mzahana Keep tracking the depenency untill you hit the offending object. In your case, otool -L /usr/local/opt/opencv3/lib/libopencv_imgcodecs.3.1.dylib If you can find a valid I don't know how you can update
I usually recommend installing OpenCV with package manager like Macports or Homebrew to avoid any of the dependency issue. But you will perhaps need to go back to OpenCV compilation and installation options to make sure the OpenCV binary is linked to the right depenency. |
Thanks for your help. I am starting to get dizzy on that 😄, but will keep trying. Here is the output of the /usr/local/opt/opencv3/lib/libopencv_imgcodecs.3.1.dylib:
/usr/local/opt/opencv3/lib/libopencv_imgcodecs.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/local/Cellar/opencv3/3.1.0_3/lib/libopencv_imgproc.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/local/opt/jpeg/lib/libjpeg.8.dylib (compatibility version 13.0.0, current version 13.0.0)
/usr/local/opt/libpng/lib/libpng16.16.dylib (compatibility version 38.0.0, current version 38.0.0)
/usr/local/opt/libtiff/lib/libtiff.5.dylib (compatibility version 8.0.0, current version 8.4.0)
/usr/local/opt/ilmbase/lib/libImath-2_2.12.dylib (compatibility version 13.0.0, current version 13.0.0)
/usr/local/opt/openexr/lib/libIlmImf-2_2.22.dylib (compatibility version 23.0.0, current version 23.0.0)
/usr/local/opt/ilmbase/lib/libIex-2_2.12.dylib (compatibility version 13.0.0, current version 13.0.0)
/usr/local/opt/ilmbase/lib/libHalf.12.dylib (compatibility version 13.0.0, current version 13.0.0)
/usr/local/opt/ilmbase/lib/libIlmThread-2_2.12.dylib (compatibility version 13.0.0, current version 13.0.0)
/usr/local/Cellar/opencv3/3.1.0_3/lib/libopencv_core.3.1.dylib (compatibility version 3.1.0, current version 3.1.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1) Any conclusions from that? |
I could notice this: /usr/local/opt/libtiff/lib/libtiff.5.dylib (compatibility version 8.0.0, current version 8.4.0) Do I need to update anything? |
@mzahana compare the output when you run
You will likely see that MATLAB loads its own libtiff library older than the one used when compiling OpenCV, in which case you need to force-load the newer one like kyamagu explained. |
this is what i get when i run
|
@mzahana What happens if you set DYLD_INSERT_LIBRARIES=/usr/local/opt/libtiff/lib/libtiff.5.dylib /Applications/MATLAB_R2015a.app/bin/matlab |
still there i a problem:
|
@mzahana According to the
The |
Ok, I am doing that now. Now, what is a clean way to install and compile Opencv3? |
@mzahana I recommend Homebrew package. See the previous comment. brew install homebrew/science/opencv3 |
OK. Here us what i got when i installed opencv3 using brew: ==> Installing opencv3 from homebrew/science
==> Downloading https://homebrew.bintray.com/bottles-science/opencv3-3.1.0_3.el_capitan.bottle.2.t
Already downloaded: /Library/Caches/Homebrew/opencv3-3.1.0_3.el_capitan.bottle.2.tar.gz
==> Pouring opencv3-3.1.0_3.el_capitan.bottle.2.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
opencv3 and opencv install many of the same files.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/opencv3/lib
CPPFLAGS: -I/usr/local/opt/opencv3/include
If you need Python to find bindings for this keg-only formula, run:
echo /usr/local/opt/opencv3/lib/python2.7/site-packages >> /usr/local/lib/python2.7/site-packages/opencv3.pth
==> Summary
🍺 /usr/local/Cellar/opencv3/3.1.0_3: 281 files, 119.9M when i run Makefile:97: *** "OpenCV 3.x package was not found in the pkg-config search path". Stop. |
@mzahana You'll need |
Stil, same problem LDFLAGS=-L/usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/3rdparty/lib/ PKG_CONFIG_OPENCV=opencv3 MATLABDIR=/Applications/MATLAB_R2015a.app make -j4
Makefile:97: *** "OpenCV 3.x package was not found in the pkg-config search path". Stop. |
@mzahana Can you post the output of the following? Homebrew usually takes care of pkg-config --exists --atleast-version=3 opencv3
echo $? pkg-config --cflags --libs opencv3 |
@mzahana If this doesn't work, you might need to force symlink. brew link --force opencv3 |
The output as as follows: pkg-config --exists --atleast-version=3 opencv3
kl-14887:mexopencv abdkadma$ echo $?
1
and pkg-config --cflags --libs opencv3
Package opencv3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv3' found |
and here is the output when I try sudo brew link --force opencv3
Linking /usr/local/Cellar/opencv3/3.1.0_3...
Error: Could not symlink lib/libopencv_calib3d.3.1.dylib
Target /usr/local/lib/libopencv_calib3d.3.1.dylib
already exists. You may want to remove it:
rm '/usr/local/lib/libopencv_calib3d.3.1.dylib'
To force the link and overwrite all conflicting files:
brew link --overwrite opencv3
To list all files that would be deleted:
brew link --overwrite --dry-run opencv3 |
I think i screwed my opencv build. I can not even When I download the opencv3 source and generate Makefile using make, then run In file included from /Users/abdkadma/Dropbox/opencv-3.1.0/modules/videoio/src/cap_qtkit.mm:46:
In file included from /System/Library/Frameworks/QTKit.framework/Headers/QTKit.h:20:
In file included from /System/Library/Frameworks/QTKit.framework/Headers/QTError.h:17:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5:
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:19:21: error:
expected a type
- (id)copyWithZone:(nullable NSZone *)zone;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:25:28: error:
expected a type
- (id)mutableCopyWithZone:(nullable NSZone *)zone;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:32:4: error:
expected a type
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder; // NS_DESIGN...
^
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:53:4: error:
expected a type
- (nullable id)replacementObjectForCoder:(NSCoder *)aCoder;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:54:4: error:
expected a type
- (nullable id)awakeAfterUsingCoder:(NSCoder *)aDecoder NS_REPLACES_RECEIVER;
^
In file included from /Users/abdkadma/Dropbox/opencv-3.1.0/modules/videoio/src/cap_qtkit.mm:46:
In file included from /System/Library/Frameworks/QTKit.framework/Headers/QTKit.h:20:
In file included from /System/Library/Frameworks/QTKit.framework/Headers/QTError.h:17:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:6:
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:7:15: error:
expected ';' after @class
@class NSArray<ObjectType>;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:7:16: error:
cannot find protocol declaration for 'ObjectType'
@class NSArray<ObjectType>;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:34:25: error:
cannot find protocol declaration for 'ObjectType'
@interface NSEnumerator<ObjectType> : NSObject <NSFastEnumeration>
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:34:37: error:
expected unqualified-id
@interface NSEnumerator<ObjectType> : NSObject <NSFastEnumeration>
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:36:4: error:
expected a type
- (nullable ObjectType)nextObject;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:25: error:
cannot find protocol declaration for 'ObjectType'
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:1: error:
duplicate interface definition for class 'NSEnumerator'
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:34:12: note:
previous definition is here
@interface NSEnumerator<ObjectType> : NSObject <NSFastEnumeration>
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:37: error:
method type specifier must start with '-' or '+'
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:38: error:
expected a type
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:1: error:
expected selector for Objective-C method
@property (readonly, copy) NSArray<ObjectType> *allObjects;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:28: error:
unknown type name 'NSArray'
@property (readonly, copy) NSArray<ObjectType> *allObjects;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:35: error:
expected member name or ';' after declaration specifiers
@property (readonly, copy) NSArray<ObjectType> *allObjects;
~~~~~~~^
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:1: error:
property requires fields to be named
@property (readonly, copy) NSArray<ObjectType> *allObjects;
^ ~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:35: error:
expected ';' at end of declaration list
@property (readonly, copy) NSArray<ObjectType> *allObjects;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_qtkit.mm.o] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2 Any ideas on what happened? |
I re-installed Xcode and I can Sorry to post this here, bu I am really looking for fast solution, and found the MATLAB support package almost working with no errors. So, I am wondering if someone can help with the MATLAB opencv support package. That package works fine, and I can
Any ideas on what could be the problem |
@mzahana I have no idea how the Mathworks support package can help here. |
Thanks for the support. I switched to the Mathworks support package for opencv, as the installation is straightforward. I wished to use this powerful tool, but the installation process, I guess, need to improve a bit. Thanks. |
Hi, I just ran into this problem with the incompatible cd /Applications/MATLAB_R2016a.app/bin/maci64
mkdir libs.bak
mv libtiff.5.dylib libs.bak/
ln -s /usr/local/opt/libtiff/lib/libtiff.5.dylib For me it was the
$ otool -L /Applications/MATLAB_R2016a.app/bin/maci64/libtiff.5.dylib
/Applications/MATLAB_R2016a.app/bin/maci64/libtiff.5.dylib:
@rpath/libtiff.5.dylib (compatibility version 6.0.0, current version 6.5.0)
(...) while $ otool -L /usr/local/opt/libtiff/lib/libtiff.5.dylib
/usr/local/opt/libtiff/lib/libtiff.5.dylib:
/usr/local/opt/libtiff/lib/libtiff.5.dylib (compatibility version 8.0.0, current version 8.4.0)
(...) After moving the library to a backup directory and symlinking the newer one in stead, the problem is gone. PS. I also tried |
@solosuper thanks, this finally got my installation working. |
@solosuper I'm having this exact same problem, however im new to homebrew so could you please tell me how to symlink the newer libraries? |
@lasuomela It's been a long time since I looked at this, so for all I know things might have changed. Anyways, the first snippet of code i posted (4 lines) did the trick for me. Everything below the line is just to describe why it worked. I'm not on a Mac right now so I can't test, but you should be able to install That command installed the required file at What my 4 lines did was to move the MATLAB-provided library out of the way (to a directory I named ln -s /usr/local/opt/libtiff/lib/libtiff.5.dylib did the so called symlinking. That means to link the homebrew-file into the current directory, which is Again, this post is from august last year, so things like |
I confirm that @solosuper's commands just worked for me. If this works for a third person, maybe it should be documented in the |
@kubark42, @solosuper, @lasuomela So in this case you would launch MATLAB as: DYLD_INSERT_LIBRARIES=/usr/local/opt/libtiff/lib/libtiff.5.dylib /Applications/MATLAB_R2016a.app/bin/matlab No need to overwrite any files. I'm not on a Mac, so can't test it myself. But I think it should work. If not, I can add the symlink approach as an alternative in the wiki... Can someone confirm please? |
@amroamroamro I don't have Matlab on Mac anymore, but it seems true that http://stackoverflow.com/questions/34114587/dyld-library-path-dyld-insert-libraries-not-working |
@kyamagu In addition to having to worry about two-level namespace executables, apparently there's also the question of whether the matlab binary is code-signed with some restrictions. From what I understood, OS X (El Capitan and above?) would then ignore all I edited the wiki page to mention the symlink method. |
@amroamroamro Thanks for the follow-up and Wiki edits. Yep, there seems no good workaround at this moment. |
The libtiff5 which loaded by matlab is from e.g. OS path = '/Applications/MATLAB_R2016a.app/bin/maci64/' (my case) and this libtiff5 in matlab OS path is version 6.0.0. So all you need to do is delete the libtiff5 or rename it as 'libtiff.5.dylib.bak.' , and create a softlink from ln from homebrew installed libtiff to matlab OS path. e.g. in my case is ln -s /usr/local/Cellar/libtiff/4.0.7_2/lib/libtiff.5.dylib /Applications/MATLAB_R2016a.app/bin/maci64/libtiff.5.dylib |
I had the same problem and the solution by @solosuper worked for me.
|
This is documented in the wiki under:
It mentions the preload method first, then symlinking as alternative. |
Hi,
I am trying to run an example to test opencv in MATLAB R2015a.
in MATLAB, I run,
I get the following error,
Invalid MEX-file '/Users/abdkadma/Dropbox/git/mexopencv/+cv/private/CascadeClassifier_.mexmaci64': dlopen(/Users/abdkadma/Dropbox/git/mexopencv/+cv/private/CascadeClassifier_.mexmaci64, 6): Library not loaded: /usr/local/opt/libtiff/lib/libtiff.5.dylib Referenced from: /usr/local/opt/opencv3/lib/libopencv_imgcodecs.3.1.dylib Reason: Incompatible library version: libopencv_imgcodecs.3.1.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
Any hints?
The text was updated successfully, but these errors were encountered: