Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Compile OS X 10.9 MATLAB 2014a #110

Closed
davesc opened this issue May 13, 2014 · 73 comments
Closed

Compile OS X 10.9 MATLAB 2014a #110

davesc opened this issue May 13, 2014 · 73 comments

Comments

@davesc
Copy link

davesc commented May 13, 2014

I get the following error when trying to compile mexopencv on OS x 10.9 with MATLAB 2014a:

make MATLABDIR=/Applications/MATLAB_R2014a.app/
/Applications/MATLAB_R2014a.app//bin/mex -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/+cv/CamShift.cpp -lMxArray -Llib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_calib3d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_contrib.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_core.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_features2d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_flann.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_gpu.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_highgui.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_imgproc.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_legacy.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ml.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_nonfree.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_objdetect.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ocl.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_photo.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_stitching.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_superres.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ts.a /usr/local/Cellar/opencv/2.4.9/lib/libopencv_video.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_videostab.dylib  -o +cv/CamShift.mexmaci64
Warning: Legacy MEX infrastructure is provided for compatibility; it will be removed in a future version of MATLAB. For more information, consult the MEX release notes http://www.mathworks.com/help/matlab/release-notes.html.
Undefined symbols for architecture x86_64:
  "cv::merge(std::vector<cv::Mat, std::allocator<cv::Mat> > const&, cv::_OutputArray const&)", referenced from:
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
  "cv::split(cv::Mat const&, std::vector<cv::Mat, std::allocator<cv::Mat> >&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

mex: link of ' "+cv/CamShift.mexmaci64"' failed.

make: **\* [+cv/CamShift.mexmaci64] Error 255

I have the matlab example mex files compiling correctly. I'm using the the mexopt.sh from this link: http://folk.ntnu.no/seljasen/Arbeider/GSL_and_openMP_mexopts.sh, which specifies gcc and gcc++ (I'm using gcc49).

Any help appreciated.

@kyamagu
Copy link
Owner

kyamagu commented May 13, 2014

Very likely you're linking against libstdc++ but not libc++, which is
the default C++ runtime for OS X 10.9. Please edit/update mexopts to
include -lstdlib flag, and possibly other options.

@davesc
Copy link
Author

davesc commented May 13, 2014

The mexopts.sh above uses -lstdc++

I tried changing the -lstdc++ flags to -lc++ in mexopts.sh, but I got a similar error "Undefined symbols for architecture x86_64:" but with even more errors listed (too many to paste in here). The matlab example mex files still compiled correctly with the new mexopts.sh

@kyamagu
Copy link
Owner

kyamagu commented May 13, 2014

Different errors mean different things. Please try to parse out errors one by one. As a reference, I have my config example here.

@davesc
Copy link
Author

davesc commented May 14, 2014

ok I started over with the original mexopts.sh that came with 2014a, and added/changed the lines in your example (link in previous comment). The MATLAB mex examples compile correctly, although they're in c not c++. When I compile mexopencv I now get the error below. I thought this line in mexopts.sh should have taken care of it:

CXXFLAGS="$CXXFLAGS -std=c++11 -stdlib=libc++ -DCHAR16_T"

make MATLABDIR=/Applications/MATLAB_R2014a.app/
/Applications/MATLAB_R2014a.app//bin/mex -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/+cv/CamShift.cpp -lMxArray -Llib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_calib3d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_contrib.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_core.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_features2d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_flann.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_gpu.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_highgui.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_imgproc.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_legacy.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ml.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_nonfree.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_objdetect.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ocl.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_photo.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_stitching.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_superres.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ts.a /usr/local/Cellar/opencv/2.4.9/lib/libopencv_video.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_videostab.dylib  -o +cv/CamShift.mexmaci64
Warning: Legacy MEX infrastructure is provided for compatibility; it will be removed in a future version of MATLAB. For more information, consult the MEX release notes http://www.mathworks.com/help/matlab/release-notes.html.
In file included from src/+cv/CamShift.cpp:7:
In file included from include/mexopencv.hpp:14:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2014a.app/extern/include/mex.h:57:
In file included from /Applications/MATLAB_R2014a.app/extern/include/matrix.h:25:
/Applications/MATLAB_R2014a.app/extern/include/tmwtypes.h:829:18: error: expected
      unqualified-id
typedef char16_t CHAR16_T;
                 ^
<command line>:2:18: note: expanded from here
#define CHAR16_T 1
                 ^
In file included from src/+cv/CamShift.cpp:7:
In file included from include/mexopencv.hpp:14:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2014a.app/extern/include/mex.h:57:
/Applications/MATLAB_R2014a.app/extern/include/matrix.h:266:9: error: expected
      unqualified-id
typedef CHAR16_T mxChar;
        ^
<command line>:2:18: note: expanded from here
#define CHAR16_T 1
                 ^
In file included from src/+cv/CamShift.cpp:7:
In file included from include/mexopencv.hpp:14:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2014a.app/extern/include/mex.h:57:
/Applications/MATLAB_R2014a.app/extern/include/matrix.h:606:37: error: unknown type
      name 'mxChar'
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxChar *mxGetChars(
                                    ^
In file included from src/+cv/CamShift.cpp:7:
In file included from include/mexopencv.hpp:14:
include/MxArray.hpp:923:51: error: unknown type name 'mxChar'
            *(mxGetChars(p_)+index) = static_cast<mxChar>(value); break;
                                                  ^
4 errors generated.

    mex: compile of ' "src/+cv/CamShift.cpp"' failed.

make: *** [+cv/CamShift.mexmaci64] Error 255

@kyamagu
Copy link
Owner

kyamagu commented May 14, 2014

Remove -DCHAR16_T if it’s not necessary in your environment. Matlab 2014a made a significant change in MEX configuration, but I don’t know what they are.

@davesc
Copy link
Author

davesc commented May 14, 2014

Removing -DCHAR16_T goes back to the errors in my first post. Still no luck

I found some good info for matlab 2013b here:
http://stackoverflow.com/questions/22367516/mex-compile-error-unknown-type-name-char16-t

but not much out there about 2014a. I'll try installing 2013b and see if I can get it working.

@davesc
Copy link
Author

davesc commented May 16, 2014

I installed 2013b and I'm getting the same errors as with 2014a

@kyamagu
Copy link
Owner

kyamagu commented May 16, 2014

Try to define CHAR16_T macro differently, like -DCHAR16_T=uint16_T, -DCHAR16_T=char16_t, etc. The definition of this macro really depends on a compiler.

@davesc
Copy link
Author

davesc commented May 19, 2014

Ok, I tried both, although I might be screwing this up (I have zero c++ skills)

When I define the macro

CXXFLAGS = "$CXXFLAGS -DCHAR16_T=char16_t"

I get this error:

make MATLABDIR=/Applications/MATLAB_R2013b.app/
/Applications/MATLAB_R2013b.app//bin/mex -c -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/MxArray.cpp -outdir lib
In file included from src/MxArray.cpp:6:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2013b.app/extern/include/mex.h:58:
In file included from /Applications/MATLAB_R2013b.app/extern/include/matrix.h:252:
/Applications/MATLAB_R2013b.app/extern/include/tmwtypes.h:831:18: error: cannot
      combine with previous 'char16_t' declaration specifier
typedef char16_t CHAR16_T;
                 ^
<command line>:2:18: note: expanded from here
#define CHAR16_T char16_t
                 ^
In file included from src/MxArray.cpp:6:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2013b.app/extern/include/mex.h:58:
In file included from /Applications/MATLAB_R2013b.app/extern/include/matrix.h:252:
/Applications/MATLAB_R2013b.app/extern/include/tmwtypes.h:831:1: warning: 
      typedef requires a name [-Wmissing-declarations]
typedef char16_t CHAR16_T;
^~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.

    mex: compile of ' "src/MxArray.cpp"' failed.

make: *** [lib/libMxArray.a] Error 255

and when I define macro

CXXFLAGS = "$CXXFLAGS -DCHAR16_T=uint16_t"

I get this error:

make MATLABDIR=/Applications/MATLAB_R2013b.app/
/Applications/MATLAB_R2013b.app//bin/mex -c -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/MxArray.cpp -outdir lib
In file included from src/MxArray.cpp:6:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2013b.app/extern/include/mex.h:58:
In file included from /Applications/MATLAB_R2013b.app/extern/include/matrix.h:252:
/Applications/MATLAB_R2013b.app/extern/include/tmwtypes.h:831:18: error: 
      typedef redefinition with different types ('char16_t' vs 'unsigned short')
typedef char16_t CHAR16_T;
                 ^
<command line>:2:18: note: expanded from here
#define CHAR16_T uint16_T
                 ^
/Applications/MATLAB_R2013b.app/extern/include/tmwtypes.h:264:19: note: 
      previous definition is here
 typedef UINT16_T uint16_T;
                  ^
1 error generated.

    mex: compile of ' "src/MxArray.cpp"' failed.

make: *** [lib/libMxArray.a] Error 255
pvsouth:mexopencv dclark$ make MATLABDIR=/Applications/MATLAB_R2013b.app/
/Applications/MATLAB_R2013b.app//bin/mex -c -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/MxArray.cpp -outdir lib
In file included from src/MxArray.cpp:6:
In file included from include/MxArray.hpp:13:
In file included from /Applications/MATLAB_R2013b.app/extern/include/mex.h:58:
In file included from /Applications/MATLAB_R2013b.app/extern/include/matrix.h:252:
/Applications/MATLAB_R2013b.app/extern/include/tmwtypes.h:831:18: error: 
      typedef redefinition with different types ('char16_t' vs 'unsigned short')
typedef char16_t CHAR16_T;
                 ^
<command line>:2:18: note: expanded from here
#define CHAR16_T uint16_t
                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk//usr/include/_types/_uint16_t.h:31:24: note: 
      previous definition is here
typedef unsigned short uint16_t;
                       ^
1 error generated.

    mex: compile of ' "src/MxArray.cpp"' failed.

@kyamagu
Copy link
Owner

kyamagu commented May 19, 2014

The error says you already have CHAR16_T defined somewhere. Then, don’t define that macro in the compile-time option.

@davesc
Copy link
Author

davesc commented May 19, 2014

oops wrote uint16_t instead of uint16_T. I get this error with uint16_T

CXXFLAGS = "$CXXFLAGS -DCHAR16_T=uint16_T"

make MATLABDIR=/Applications/MATLAB_R2013b.app/
/Applications/MATLAB_R2013b.app//bin/mex -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/+cv/CamShift.cpp -lMxArray -Llib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_calib3d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_contrib.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_core.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_features2d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_flann.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_gpu.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_highgui.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_imgproc.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_legacy.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ml.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_nonfree.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_objdetect.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ocl.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_photo.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_stitching.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_superres.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ts.a /usr/local/Cellar/opencv/2.4.9/lib/libopencv_video.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_videostab.dylib  -o +cv/CamShift.mexmaci64
Undefined symbols for architecture x86_64:
  "cv::merge(std::vector<cv::Mat, std::allocator<cv::Mat> > const&, cv::_OutputArray const&)", referenced from:
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
  "cv::split(cv::Mat const&, std::vector<cv::Mat, std::allocator<cv::Mat> >&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
  "std::string::compare(char const*) const", referenced from:
      MxArray::toRange() const in libMxArray.a(MxArray.o)
  "std::string::_Rep::_M_destroy(std::allocator<char> const&)", referenced from:
      MxArray::MxArray(cv::Moments const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::KeyPoint const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::KeyPoint>(std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::DMatch const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::DMatch>(std::vector<cv::DMatch, std::allocator<cv::DMatch> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::RotatedRect const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::TermCriteria const&) in libMxArray.a(MxArray.o)
      ...
  "std::string::_Rep::_S_empty_rep_storage", referenced from:
      MxArray::MxArray(cv::Moments const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::KeyPoint const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::KeyPoint>(std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::DMatch const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::DMatch>(std::vector<cv::DMatch, std::allocator<cv::DMatch> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::RotatedRect const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::TermCriteria const&) in libMxArray.a(MxArray.o)
      ...
  "std::string::assign(std::string const&)", referenced from:
      std::vector<std::string, std::allocator<std::string> >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string, std::allocator<std::string> > >, std::string const&) in libMxArray.a(MxArray.o)
      __GLOBAL__I_a in libMxArray.a(MxArray.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
      MxArray::MxArray(cv::Moments const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::KeyPoint const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::KeyPoint>(std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::DMatch const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::DMatch>(std::vector<cv::DMatch, std::allocator<cv::DMatch> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::RotatedRect const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::TermCriteria const&) in libMxArray.a(MxArray.o)
      ...
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)", referenced from:
      MxArray::MxArray(cv::TermCriteria const&) in libMxArray.a(MxArray.o)
      MxArray::fieldnames() const in libMxArray.a(MxArray.o)
      std::vector<std::string, std::allocator<std::string> > MxArray::toVector<std::string>(std::const_mem_fun_ref_t<std::string, MxArray>) const in libMxArray.a(MxArray.o)
      std::vector<std::string, std::allocator<std::string> >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string, std::allocator<std::string> > >, std::string const&) in libMxArray.a(MxArray.o)
      std::string* std::vector<std::string, std::allocator<std::string> >::_M_allocate_and_copy<std::string*>(unsigned long, std::string*, std::string*) in libMxArray.a(MxArray.o)
      std::map<std::string, int, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::operator[](std::string const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<std::string, std::pair<std::string const, int>, std::_Select1st<std::pair<std::string const, int> >, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::_M_create_node(std::pair<std::string const, int> const&) in libMxArray.a(MxArray.o)
      ...
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__I_a in libMxArray.a(MxArray.o)
  "std::ios_base::Init::~Init()", referenced from:
      __GLOBAL__I_a in libMxArray.a(MxArray.o)
  "std::_Rb_tree_decrement(std::_Rb_tree_node_base*)", referenced from:
      std::_Rb_tree<std::string, std::pair<std::string const, int>, std::_Select1st<std::pair<std::string const, int> >, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<std::string const, int> >, std::pair<std::string const, int> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<std::string, std::pair<std::string const, int>, std::_Select1st<std::pair<std::string const, int> >, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::_M_insert_unique(std::pair<std::string const, int> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, std::string>, std::_Select1st<std::pair<int const, std::string> >, std::less<int>, std::allocator<std::pair<int const, std::string> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::pair<int const, std::string> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, std::string>, std::_Select1st<std::pair<int const, std::string> >, std::less<int>, std::allocator<std::pair<int const, std::string> > >::_M_insert_unique(std::pair<int const, std::string> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, mxClassID>, std::_Select1st<std::pair<int const, mxClassID> >, std::less<int>, std::allocator<std::pair<int const, mxClassID> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<int const, mxClassID> >, std::pair<int const, mxClassID> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, mxClassID>, std::_Select1st<std::pair<int const, mxClassID> >, std::less<int>, std::allocator<std::pair<int const, mxClassID> > >::_M_insert_unique(std::pair<int const, mxClassID> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<mxClassID, std::pair<mxClassID const, int>, std::_Select1st<std::pair<mxClassID const, int> >, std::less<mxClassID>, std::allocator<std::pair<mxClassID const, int> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<mxClassID const, int> >, std::pair<mxClassID const, int> const&) in libMxArray.a(MxArray.o)
      ...
  "std::_Rb_tree_increment(std::_Rb_tree_node_base*)", referenced from:
      std::_Rb_tree<std::string, std::pair<std::string const, int>, std::_Select1st<std::pair<std::string const, int> >, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<std::string const, int> >, std::pair<std::string const, int> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, std::string>, std::_Select1st<std::pair<int const, std::string> >, std::less<int>, std::allocator<std::pair<int const, std::string> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::pair<int const, std::string> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, mxClassID>, std::_Select1st<std::pair<int const, mxClassID> >, std::less<int>, std::allocator<std::pair<int const, mxClassID> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<int const, mxClassID> >, std::pair<int const, mxClassID> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<mxClassID, std::pair<mxClassID const, int>, std::_Select1st<std::pair<mxClassID const, int> >, std::less<mxClassID>, std::allocator<std::pair<mxClassID const, int> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<mxClassID const, int> >, std::pair<mxClassID const, int> const&) in libMxArray.a(MxArray.o)
  "std::__throw_length_error(char const*)", referenced from:
      MxArray::MxArray(cv::SparseMat const&) in libMxArray.a(MxArray.o)
      std::vector<std::string, std::allocator<std::string> >::reserve(unsigned long) in libMxArray.a(MxArray.o)
      std::vector<MxArray, std::allocator<MxArray> >::reserve(unsigned long) in libMxArray.a(MxArray.o)
      std::vector<cv::Mat, std::allocator<cv::Mat> >::reserve(unsigned long) in libMxArray.a(MxArray.o)
      std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >::reserve(unsigned long) in libMxArray.a(MxArray.o)
      std::vector<cv::DMatch, std::allocator<cv::DMatch> >::reserve(unsigned long) in libMxArray.a(MxArray.o)
      std::vector<cv::DMatch, std::allocator<cv::DMatch> >::_M_insert_aux(__gnu_cxx::__normal_iterator<cv::DMatch*, std::vector<cv::DMatch, std::allocator<cv::DMatch> > >, cv::DMatch const&) in libMxArray.a(MxArray.o)
      ...
  "std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)", referenced from:
      std::_Rb_tree<std::string, std::pair<std::string const, int>, std::_Select1st<std::pair<std::string const, int> >, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<std::string const, int> >, std::pair<std::string const, int> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<std::string, std::pair<std::string const, int>, std::_Select1st<std::pair<std::string const, int> >, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >::_M_insert_unique(std::pair<std::string const, int> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, std::string>, std::_Select1st<std::pair<int const, std::string> >, std::less<int>, std::allocator<std::pair<int const, std::string> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::pair<int const, std::string> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, std::string>, std::_Select1st<std::pair<int const, std::string> >, std::less<int>, std::allocator<std::pair<int const, std::string> > >::_M_insert_unique(std::pair<int const, std::string> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, mxClassID>, std::_Select1st<std::pair<int const, mxClassID> >, std::less<int>, std::allocator<std::pair<int const, mxClassID> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<int const, mxClassID> >, std::pair<int const, mxClassID> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<int, std::pair<int const, mxClassID>, std::_Select1st<std::pair<int const, mxClassID> >, std::less<int>, std::allocator<std::pair<int const, mxClassID> > >::_M_insert_unique(std::pair<int const, mxClassID> const&) in libMxArray.a(MxArray.o)
      std::_Rb_tree<mxClassID, std::pair<mxClassID const, int>, std::_Select1st<std::pair<mxClassID const, int> >, std::less<mxClassID>, std::allocator<std::pair<mxClassID const, int> > >::_M_insert_unique(std::_Rb_tree_iterator<std::pair<mxClassID const, int> >, std::pair<mxClassID const, int> const&) in libMxArray.a(MxArray.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    mex: link of ' "+cv/CamShift.mexmaci64"' failed.

make: *** [+cv/CamShift.mexmaci64] Error 255

@kyamagu
Copy link
Owner

kyamagu commented May 19, 2014

The Undefined symbols error is because you don't have -std=c++11 -stdlib=libc++ options. String-related errors are due to your incorrect CHAR16_T option.

@davesc
Copy link
Author

davesc commented May 19, 2014

@ previous comment:
I did have -std=c++11 -stdlib=libc++ options in there

I got this working, see next comment

@davesc
Copy link
Author

davesc commented May 19, 2014

Here is what I did to get mexopencv working in MATLAB 2013b and 2014a running OS X 10.9 and Xcode 5.1

I edited mexopts.sh following your link
https://gist.github.com/kyamagu/8363310
but I removed the -DCHAR16_T from the CXXFLAGS. I tried this earlier but must have had a bug somewhere else, anyway it works now. In mexopts.sh you can use CC='clang' or CC='xcrun -sdk macosx10.9 clang', both work, same goes for the CXX line (but with clang++).

I needed to link the non-matlab version of libtiff when starting matlab:

DYLD_INSERT_LIBRARIES=/usr/local/lib/libtiff.5.dylib /Applications/MATLAB_R2013b.app/bin/matlab & 

I had to move the matlab builtin opencv so the mexopencv functions didn't find it, so I made a new directory called libopencv in /Applications/MATLAB_R2014a.app/bin/maci64/ and moved all the matlab opencv libraries in there

mkdir /Applications/MATLAB_R2014a.app/bin/maci64/libopencv
mv /Applications/MATLAB_R2014a.app/bin/maci64/libopencv_* Applications/MATLAB_R2014a.app/bin/maci64/libopencv

I'll write up a how to for dummies (like me) in a following post. There are a lot of people in the scientific community who could use mexopencv but aren't c++ savy

@davesc
Copy link
Author

davesc commented May 20, 2014

Here is what I did to get mexopencv working in MATLAB 2013b and 2014a running OS X 10.9 and Xcode 5.1. All my packages are installed using Homebrew (everything in /usr/local/bin).

Edit your 'mexopts.sh' file, located at
'/Applications/MATLAB_R2014a.app/bin/mexopts.sh'. Do not use TextEdit to edit mexopts.sh, it will autocorrect single quotes and your shell script won't work. Use TextWrangler, BBEdit, vim, or similar.
Scroll down to the maci64 section (near the bottom) and change:
CC='xcrun -sdk macosx10.7 clang' to CC='xcrun -sdk macosx10.9 clang'

change
MW_SDKROOT_TMP="find``xcode-select -print-path``-name MacOSX10.7.sdk" to MW_SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'

after CFLAGS="$CFLAGS -fexceptions" add a new line: CFLAGS="$CFLAGS -Dchar16_t=uint16_t"

change CXX='xcrun -sdk macosx10.7 clang++' to CXX='xcrun -sdk macosx10.9 clang++'

after CXXFLAGS="-fno-common -fexceptions -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET" add a new line: CXXFLAGS="$CXXFLAGS -std=c++11 -stdlib=libc++"


Now compile mexopencv: make MATLABDIR=/Applications/MATLAB_R2014a.app


Add the non-matlab version of libtiff when starting matlab DYLD_INSERT_LIBRARIES=/usr/local/lib/libtiff.5.dylib /Applications/MATLAB_R2013b.app/bin/matlab &
or you can rename the matlab version of libtiff /Applications/MATLAB_R2014a.app/bin/maci64/libtiff.5.dylib to something else so matlab can't find it (this might cause problems for other matlab functions)

@davesc
Copy link
Author

davesc commented May 20, 2014

thanks for your help

@ray-z
Copy link

ray-z commented Oct 28, 2014

Followed @davesc 's last comment, I got this error messages:

/Applications/MATLAB_R2013a.app/bin/mex -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/+cv/CamShift.cpp -lMxArray -Llib  -output +cv/CamShift.mexmaci64
clang: warning: no such sysroot directory: '-mmacosx-version-min=10.9'
In file included from src/+cv/CamShift.cpp:7:
In file included from include/mexopencv.hpp:14:
In file included from include/MxArray.hpp:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:477:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:600:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:332:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:10: fatal error:
      'wchar.h' file not found
#include <wchar.h>  // for mbstate_t
         ^
1 error generated.

    mex: compile of ' "src/+cv/CamShift.cpp"' failed.

make: *** [+cv/CamShift.mexmaci64] Error 1

I'm using Yosemite, and I check there still exist MacOSX10.9.sdk. Any ideas?

@kyamagu
Copy link
Owner

kyamagu commented Oct 28, 2014

@ray-z

Did you install Xcode CL tools? xcode-select --install

@ray-z
Copy link

ray-z commented Oct 28, 2014

Yes.

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

I'm using Xcode 6.1

@kyamagu
Copy link
Owner

kyamagu commented Oct 28, 2014

Then perhaps the mex configuration file has a wrong flag. The relevant line in your output is:

clang: warning: no such sysroot directory: '-mmacosx-version-min=10.9'

From this, I suspect that your mexopts.sh (or xml file if Matlab R2014) contains a wrong value for -isysroot flag in CFLAGS. Check that you don't have a wrong entry in the config.

@ray-z
Copy link

ray-z commented Oct 28, 2014

CFLAGS="-fno-common -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"

CXXFLAGS="-fno-common -fexceptions -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"

I have those 2 lines contain -isysroot. I'm using MATLAB 2013a.

@ray-z
Copy link

ray-z commented Oct 28, 2014

MW_SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'

This points to correct directory.

@kyamagu
Copy link
Owner

kyamagu commented Oct 28, 2014

Can you add -v flag (verbose flag) in mex command? Edit Makefile and just add -v. You can see what exact compiler flags are passed.

@ray-z
Copy link

ray-z commented Oct 28, 2014

Sorry, did you mean edit this line?

MEX         ?= $(MATLABDIR)/bin/mex

@kyamagu
Copy link
Owner

kyamagu commented Oct 28, 2014

You can add -v after that, or add -v to C_FLAGS.

@ray-z
Copy link

ray-z commented Oct 28, 2014

I got this:

/Applications/MATLAB_R2013a.app/bin/mex -v -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/+cv/CamShift.cpp -lMxArray -Llib  -output +cv/CamShift.mexmaci64
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
   FILE = /Users/Ray/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /Applications/MATLAB_R2013a.app
->    CC                    = xcrun  -sdk macosx10.9  clang
->    CC flags:
         CFLAGS             = -fno-common -arch x86_64 -isysroot  -mmacosx-version-min=10.9  -fexceptions -Dchar16_t=uint16_t
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O2 -DNDEBUG
         CLIBS              = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
         arguments          =
->    CXX                   = xcrun  -sdk macosx10.9  clang++
->    CXX flags:
         CXXFLAGS           = -fno-common -fexceptions -arch x86_64 -isysroot  -mmacosx-version-min=10.9 -std=c++11 -stdlib=libc++
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O2 -DNDEBUG
         CXXLIBS            = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
         arguments          =
->    FC                    = gfortran
->    FC flags:
         FFLAGS             = -fexceptions -m64 -fbackslash
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
         arguments          =
->    LD                    = xcrun -sdk macosx10.9 clang
->    Link flags:
         LDFLAGS            = -arch x86_64 -Wl,-syslibroot, -mmacosx-version-min=10.9 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexmaci64
         arguments          =  -lMxArray -Llib
->    LDCXX                 =
->    Link flags:
         LDCXXFLAGS         =
         LDCXXDEBUGFLAGS    =
         LDCXXOPTIMFLAGS    =
         LDCXXEXTENSION     =
         arguments          =  -lMxArray -Llib
----------------------------------------------------------------

-> xcrun  -sdk macosx10.9  clang++ -c  -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include -I/Applications/MATLAB_R2013a.app/extern/include -I/Applications/MATLAB_R2013a.app/simulink/include -DMATLAB_MEX_FILE -fno-common -fexceptions -arch x86_64 -isysroot  -mmacosx-version-min=10.9 -std=c++11 -stdlib=libc++  -O2 -DNDEBUG  "src/+cv/CamShift.cpp"

clang: warning: no such sysroot directory: '-mmacosx-version-min=10.9'
In file included from src/+cv/CamShift.cpp:7:
In file included from include/mexopencv.hpp:14:
In file included from include/MxArray.hpp:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:477:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:600:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:332:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:10: fatal error:
      'wchar.h' file not found
#include <wchar.h>  // for mbstate_t
         ^
1 error generated.

    mex: compile of ' "src/+cv/CamShift.cpp"' failed.

make: *** [+cv/CamShift.mexmaci64] Error 1

@kyamagu
Copy link
Owner

kyamagu commented Oct 28, 2014

Apparently MW_SDKROOT is empty here. Check back your config (mexopts.sh) and try to change SDKROOT.

@ray-z
Copy link

ray-z commented Oct 28, 2014

You are right! I need remove MW_SDKROOT=$MW_SDK_TEMP``
Now I have the same error as @davesc :

/Applications/MATLAB_R2013a.app/bin/mex  -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.9/include/opencv -I/usr/local/Cellar/opencv/2.4.9/include  src/+cv/CamShift.cpp -lMxArray -Llib  -output +cv/CamShift.mexmaci64
Undefined symbols for architecture x86_64:
  "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
      _mexFunction in CamShift.o
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
  "cv::_InputArray::_InputArray(double const&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
  "cv::_OutputArray::_OutputArray(cv::Mat&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
  "cv::SparseMatConstIterator::SparseMatConstIterator(cv::SparseMat const*)", referenced from:
      MxArray::MxArray(cv::SparseMat const&) in libMxArray.a(MxArray.o)
  "cv::SparseMatConstIterator::operator++()", referenced from:
      MxArray::MxArray(cv::SparseMat const&) in libMxArray.a(MxArray.o)
  "cv::Mat::deallocate()", referenced from:
      _mexFunction in CamShift.o
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
      std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> > MxArray::toVector<cv::Mat>() const in libMxArray.a(MxArray.o)
      cv::MatExpr::operator cv::Mat() const in libMxArray.a(MxArray.o)
      std::__1::__split_buffer<cv::Mat, std::__1::allocator<cv::Mat>&>::~__split_buffer() in libMxArray.a(MxArray.o)
      ...
  "cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
  "cv::Mat::create(int, int const*, int)", referenced from:
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
  "cv::Mat::copySize(cv::Mat const&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
      std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> > MxArray::toVector<cv::Mat>() const in libMxArray.a(MxArray.o)
      void std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >::__push_back_slow_path<cv::Mat const>(cv::Mat const&) in libMxArray.a(MxArray.o)
      std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >::__swap_out_circular_buffer(std::__1::__split_buffer<cv::Mat, std::__1::allocator<cv::Mat>&>&) in libMxArray.a(MxArray.o)
  "cv::Mat::Mat(int, int const*, int, void*, unsigned long const*)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
  "cv::merge(std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> > const&, cv::_OutputArray const&)", referenced from:
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
  "cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
  "cv::Moments::Moments(double, double, double, double, double, double, double, double, double, double)", referenced from:
      MxArray::toMoments(unsigned long) const in libMxArray.a(MxArray.o)
  "cv::compare(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
  "cv::CamShift(cv::_InputArray const&, cv::Rect_<int>&, cv::TermCriteria)", referenced from:
      _mexFunction in CamShift.o
  "cv::fastFree(void*)", referenced from:
      _mexFunction in CamShift.o
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
      std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> > MxArray::toVector<cv::Mat>() const in libMxArray.a(MxArray.o)
      cv::MatExpr::operator cv::Mat() const in libMxArray.a(MxArray.o)
      std::__1::__split_buffer<cv::Mat, std::__1::allocator<cv::Mat>&>::~__split_buffer() in libMxArray.a(MxArray.o)
      ...
  "cv::SparseMat::ptr(int, int, bool, unsigned long*)", referenced from:
      MxArray::toSparseMat() const in libMxArray.a(MxArray.o)
  "cv::SparseMat::create(int, int const*, int)", referenced from:
      MxArray::toSparseMat() const in libMxArray.a(MxArray.o)
  "cv::Mat::t() const", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
  "cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const", referenced from:
      MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      MxArray::toMatND(int, bool) const in libMxArray.a(MxArray.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    mex: link of ' "+cv/CamShift.mexmaci64"' failed.

make: *** [+cv/CamShift.mexmaci64] Error 1

I tried to add -DCHAR16_T=uint16_T or -DCHAR16_T=char16_t in the Makefile, no luck. I don't really understand how he worked it out.

@ray-z
Copy link

ray-z commented Oct 28, 2014

Could you post you mexopts.sh here, so I can have a try?

@haipz
Copy link

haipz commented May 8, 2015

I run the code below:

>> mexopencv.make('extra','-I /usr/local/Cellar/opencv/2.4.11/include -L /usr/local/Cellar/opencv/2.4.11/lib/')

and I got the result:

make MATLABDIR="/Applications/MATLAB_R2014b.app" MEXEXT=mexmaci64  -I /usr/local/Cellar/opencv/2.4.11/include -L /usr/local/Cellar/opencv/2.4.11/lib/
make: Nothing to be done for `/usr/local/Cellar/opencv/2.4.11/lib/'.

Then how to solve this problem please? T . T

@kyamagu
Copy link
Owner

kyamagu commented May 8, 2015

@haipz What do you get if you type the following in UNIX shell (not in matlab)

make MATLABDIR="/Applications/MATLAB_R2014b.app" MEXEXT=mexmaci64 -I/usr/local/Cellar/opencv/2.4.11/include -L/usr/local/Cellar/opencv/2.4.11/lib

@haipz
Copy link

haipz commented May 8, 2015

I run the code in iTerm2, and got this:

/Applications/Xcode.app/Contents/Developer/usr/bin/make: invalid option -- /
/Applications/Xcode.app/Contents/Developer/usr/bin/make: invalid option -- u
/Applications/Xcode.app/Contents/Developer/usr/bin/make: invalid option -- /
Usage: make [options] [target] ...
Options:
  -b, -m                      Ignored for compatibility.
  -B, --always-make           Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.
  -d                          Print lots of debugging information.
  --debug[=FLAGS]             Print various types of debugging information.
  -e, --environment-overrides
                              Environment variables override makefiles.
  -f FILE, --file=FILE, --makefile=FILE
                              Read FILE as a makefile.
  -h, --help                  Print this message and exit.
  -i, --ignore-errors         Ignore errors from commands.
  -I DIRECTORY, --include-dir=DIRECTORY
                              Search DIRECTORY for included makefiles.
  -j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.
  -k, --keep-going            Keep going when some targets can't be made.
  -l [N], --load-average[=N], --max-load[=N]
                              Don't start multiple jobs unless load is below N.
  -L, --check-symlink-times   Use the latest mtime between symlinks and target.
  -n, --just-print, --dry-run, --recon
                              Don't actually run any commands; just print them.
  -o FILE, --old-file=FILE, --assume-old=FILE
                              Consider FILE to be very old and don't remake it.
  -p, --print-data-base       Print make's internal database.
  -q, --question              Run no commands; exit status says if up to date.
  -r, --no-builtin-rules      Disable the built-in implicit rules.
  -R, --no-builtin-variables  Disable the built-in variable settings.
  -s, --silent, --quiet       Don't echo commands.
  -S, --no-keep-going, --stop
                              Turns off -k.
  -t, --touch                 Touch targets instead of remaking them.
  -v, --version               Print the version number of make and exit.
  -w, --print-directory       Print the current directory.
  --no-print-directory        Turn off -w, even if it was turned on implicitly.
  -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
                              Consider FILE to be infinitely new.
  --warn-undefined-variables  Warn when an undefined variable is referenced.
  -N OPTION, --NeXT-option=OPTION
                              Turn on value of NeXT OPTION.

This program built for i386-apple-darwin11.3.0
Report bugs to <bug-make@gnu.org>

I success installed mexopencv the day before yesterday after read this issues, but there have something wrong with matlab and I can not open matlab, so I reinstall mexopencv today and got lots of error.

@kyamagu
Copy link
Owner

kyamagu commented May 8, 2015

Oops, that was not the solution. Basically you cannot have whitespace between -I, -L options and paths.

mexopencv.make('extra','-I/usr/local/Cellar/opencv/2.4.11/include -L/usr/local/Cellar/opencv/2.4.11/lib/')

@haipz
Copy link

haipz commented May 8, 2015

Oh, you are right.
I run this in matlab:

mexopencv.make('extra','-I/usr/local/Cellar/opencv/2.4.11/include -L/usr/local/Cellar/opencv/2.4.11/lib/')

and got the same error:

make MATLABDIR="/Applications/MATLAB_R2014b.app" MEXEXT=mexmaci64  -I/usr/local/Cellar/opencv/2.4.11/include -L/usr/local/Cellar/opencv/2.4.11/lib/
/Applications/Xcode.app/Contents/Developer/usr/bin/make: invalid option -- /
/Applications/Xcode.app/Contents/Developer/usr/bin/make: invalid option -- u
/Applications/Xcode.app/Contents/Developer/usr/bin/make: invalid option -- /
Usage: make [options] [target] ...
Options:
  -b, -m                      Ignored for compatibility.
  -B, --always-make           Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.
  -d                          Print lots of debugging information.
  --debug[=FLAGS]             Print various types of debugging information.
  -e, --environment-overrides
                              Environment variables override makefiles.
  -f FILE, --file=FILE, --makefile=FILE
                              Read FILE as a makefile.
  -h, --help                  Print this message and exit.
  -i, --ignore-errors         Ignore errors from commands.
  -I DIRECTORY, --include-dir=DIRECTORY
                              Search DIRECTORY for included makefiles.
  -j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.
  -k, --keep-going            Keep going when some targets can't be made.
  -l [N], --load-average[=N], --max-load[=N]
                              Don't start multiple jobs unless load is below N.
  -L, --check-symlink-times   Use the latest mtime between symlinks and target.
  -n, --just-print, --dry-run, --recon
                              Don't actually run any commands; just print them.
  -o FILE, --old-file=FILE, --assume-old=FILE
                              Consider FILE to be very old and don't remake it.
  -p, --print-data-base       Print make's internal database.
  -q, --question              Run no commands; exit status says if up to date.
  -r, --no-builtin-rules      Disable the built-in implicit rules.
  -R, --no-builtin-variables  Disable the built-in variable settings.
  -s, --silent, --quiet       Don't echo commands.
  -S, --no-keep-going, --stop
                              Turns off -k.
  -t, --touch                 Touch targets instead of remaking them.
  -v, --version               Print the version number of make and exit.
  -w, --print-directory       Print the current directory.
  --no-print-directory        Turn off -w, even if it was turned on implicitly.
  -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
                              Consider FILE to be infinitely new.
  --warn-undefined-variables  Warn when an undefined variable is referenced.
  -N OPTION, --NeXT-option=OPTION
                              Turn on value of NeXT OPTION.

This program built for i386-apple-darwin11.3.0
Report bugs to <bug-make@gnu.org>

@kyamagu
Copy link
Owner

kyamagu commented May 8, 2015

@haipz Hold on a second. You don't need to specify any extra in OS X. Just make sure your pkg-config is working fine.

@haipz
Copy link

haipz commented May 8, 2015

I reinstall the pkg-config by the code below:

sudo brew uninstall pkg-config
sudo brew install pkg-config
sudo brew link --overwrite pkg-config

and check the path of pkg-config, the content of file ~/.bash_profile is:


# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

export PKG_CONFIG_PATH="/usr/X11/lib/pkgconfig:/usr/local/Cellar/cairo/1.14.2/lib/pkgconfig"

Is it any wrong?

@kyamagu
Copy link
Owner

kyamagu commented May 8, 2015

@haipz I don't know your specific setting, but if things are set up correctly, you would see compiler flags by

pkg-config --cflags --libs opencv

If nothing is showing up, you probably have messed up your environment.

@haipz
Copy link

haipz commented May 8, 2015

Unluckly, I got this:

pkg-config --cflags --libs opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

:-( I try my limited knowledge to solve this problem, but it doesn't work.

@kyamagu
Copy link
Owner

kyamagu commented May 8, 2015

@haipz do brew install opencv to install OpenCV, or add your opencv.pc file somewhere to PKG_CONFIG_PATH variable.

@haipz
Copy link

haipz commented May 8, 2015

I solved the pkg-config problem.
First of all, I reinstall opencv by use:

sudo brew uninstall opencv
sudo brew install opencv

Second, I found something wrong with ~/.bash_profile:

export PKG_CONFIG_PATH="/usr/X11/lib/pkgconfig":"/usr/local/Cellar/cairo/1.14.2/lib/pkgconfig":"/usr/local/Cellar/opencv/2.4.11/lib/pkgconfig"

Finally, I got this in iTerm2:

***MacBook-Pro% source ~/.bash_profile
***MacBook-Pro% echo $PKG_CONFIG_PATH
/usr/X11/lib/pkgconfig:/usr/local/Cellar/cairo/1.14.2/lib/pkgconfig:/usr/local/Cellar/opencv/2.4.11/lib/pkgconfig
***MacBook-Pro% pkg-config --cflags --libs opencv
-I/usr/local/Cellar/opencv/2.4.11/include/opencv -I/usr/local/Cellar/opencv/2.4.11/include -L/usr/local/Cellar/opencv/2.4.11/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab

But it is still the same wrong with mexopencv.make('extra','-I/usr/local/Cellar/opencv/2.4.11/include -L/usr/local/Cellar/opencv/2.4.11/lib/') in matlab. I guess there must something wrong in XCode or cmake.

@kyamagu
Copy link
Owner

kyamagu commented May 8, 2015

@haipz No, you don't need any extra.

mexopencv.make()

@haipz
Copy link

haipz commented May 9, 2015

I try to make with mexopencv.make(), but I got this:

>> mexopencv.make()
make MATLABDIR="/Applications/MATLAB_R2014b.app" MEXEXT=mexmaci64  
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
/Applications/MATLAB_R2014b.app/bin/mex -c -cxx -largeArrayDims -Iinclude  src/MxArray.cpp -outdir lib
警告: 为了实现兼容性而提供了旧的 MEX 基础结构;在以后的 MATLAB 版本中将会删除该基础结构。有关详细信息,请查阅 MEX 发行说明 http://www.mathworks.com/help/matlab/release-notes.html。
In file included from src/MxArray.cpp:6:
include/MxArray.hpp:14:10: fatal error: 'opencv2/opencv.hpp' file not found
#include "opencv2/opencv.hpp"
         ^
1 error generated.

    mex: compile of ' "src/MxArray.cpp"' failed.

make: *** [lib/libMxArray.a] Error 255

and I really don't know why this happen:

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

UPDATE

I just to link opencv.pc by using:

sudo ln -s /usr/local/Cellar/opencv/2.4.11/lib/pkgconfig/opencv.pc /usr/local/lib/pkgconfig/opencv.pc

and I run mexopencv.make() in matlab:

make MATLABDIR="/Applications/MATLAB_R2014b.app" MEXEXT=mexmaci64  
/Applications/MATLAB_R2014b.app/bin/mex -c -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.11/include/opencv -I/usr/local/Cellar/opencv/2.4.11/include  src/MxArray.cpp -outdir lib
警告: 为了实现兼容性而提供了旧的 MEX 基础结构;在以后的 MATLAB 版本中将会删除该基础结构。有关详细信息,请查阅 MEX 发行说明 http://www.mathworks.com/help/matlab/release-notes.html。
ar -cq lib/libMxArray.a lib/*.o
rm -f lib/*.o
/Applications/MATLAB_R2014b.app/bin/mex -cxx -largeArrayDims -Iinclude -I/usr/local/Cellar/opencv/2.4.11/include/opencv -I/usr/local/Cellar/opencv/2.4.11/include  src/+cv/CamShift.cpp -lMxArray -Llib -L/usr/local/Cellar/opencv/2.4.11/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab   -output +cv/CamShift
警告: 为了实现兼容性而提供了旧的 MEX 基础结构;在以后的 MATLAB 版本中将会删除该基础结构。有关详细信息,请查阅 MEX 发行说明 http://www.mathworks.com/help/matlab/release-notes.html。
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
      _mexFunction in CamShift.o
      MxArray::toRange() const in libMxArray.a(MxArray.o)
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      std::__1::vector<MxArray, std::__1::allocator<MxArray> >::vector<mxArray_tag const**>(mxArray_tag const**, std::__1::enable_if<(__is_forward_iterator<mxArray_tag const**>::value) && (is_constructible<MxArray, std::__1::iterator_traits<mxArray_tag const**>::reference>::value), mxArray_tag const**>::type) in CamShift.o
      MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
      void std::__1::vector<cv::DMatch, std::__1::allocator<cv::DMatch> >::__push_back_slow_path<cv::DMatch>(cv::DMatch&&) in libMxArray.a(MxArray.o)
      void std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> >::__push_back_slow_path<cv::KeyPoint>(cv::KeyPoint&&) in libMxArray.a(MxArray.o)
      void std::__1::vector<cv::Point3_<float>, std::__1::allocator<cv::Point3_<float> > >::__push_back_slow_path<cv::Point3_<float> >(cv::Point3_<float>&&) in libMxArray.a(MxArray.o)
      void std::__1::vector<cv::Point_<float>, std::__1::allocator<cv::Point_<float> > >::__push_back_slow_path<cv::Point_<float> >(cv::Point_<float>&&) in libMxArray.a(MxArray.o)
      void std::__1::vector<cv::Point_<int>, std::__1::allocator<cv::Point_<int> > >::__push_back_slow_path<cv::Point_<int> >(cv::Point_<int>&&) in libMxArray.a(MxArray.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      __GLOBAL__sub_I_CamShift.cpp in CamShift.o
      MxArray::MxArray(cv::Moments const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::KeyPoint const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::KeyPoint>(std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::DMatch const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::DMatch>(std::__1::vector<cv::DMatch, std::__1::allocator<cv::DMatch> > const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::RotatedRect const&) in libMxArray.a(MxArray.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> > >::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in CamShift.o
      std::__1::__tree_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long> std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> > >::__insert_unique<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> const&>(std::__1::__tree_const_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long>, std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> const&&&) in CamShift.o
      MxArray::MxArray(cv::TermCriteria const&) in libMxArray.a(MxArray.o)
      std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> > >::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMxArray.a(MxArray.o)
      std::__1::__tree_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long> std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> > >::__insert_unique<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> const&>(std::__1::__tree_const_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long>, std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> const&&&) in libMxArray.a(MxArray.o)
      std::__1::__tree_iterator<std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::__tree_node<std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, void*>*, long> std::__1::__tree<std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::__map_value_compare<int, std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::less<int>, true>, std::__1::allocator<std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::__insert_unique<std::__1::pair<int const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&>(std::__1::__tree_const_iterator<std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::__tree_node<std::__1::__value_type<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, void*>*, long>, std::__1::pair<int const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&&&) in libMxArray.a(MxArray.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      _mexFunction in CamShift.o
      std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> > >::destroy(std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*) in CamShift.o
      std::__1::__tree_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long> std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> > >::__insert_unique<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> const&>(std::__1::__tree_const_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long>, std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> const&&&) in CamShift.o
      __GLOBAL__sub_I_CamShift.cpp in CamShift.o
      MxArray::MxArray(cv::Moments const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray(cv::KeyPoint const&) in libMxArray.a(MxArray.o)
      MxArray::MxArray<cv::KeyPoint>(std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> > const&) in libMxArray.a(MxArray.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      __GLOBAL__sub_I_MxArray.cpp in libMxArray.a(MxArray.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    mex: link of ' "+cv/CamShift.mexmaci64"' failed.

make: *** [+cv/CamShift.mexmaci64] Error 255

I am still trying to solve the new issuse.

UPDATE AGAIN

I edit ~/.matlab/R2014b/mexopts.sh by replacing all -lstdc++ with -lc++, and finally mexopencv.make() work. Then I do some test work by facedetect, and got this:

Face detection demo. Press any key when done.
Invalid MEX-file
'/Users/haipz/Desktop/Workspace/Matlab/mexopencv-master/+cv/private/CascadeClassifier_.mexmaci64':
dlopen(/Users/haipz/Desktop/Workspace/Matlab/mexopencv-master/+cv/private/CascadeClassifier_.mexmaci64,
6): Library not loaded: /usr/local/lib/libtiff.5.dylib
  Referenced from: /Applications/MATLAB_R2014b.app/bin/maci64/libopencv_highgui.2.4.dylib
  Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 8.0.0 or
  later, but libtiff.5.dylib provides version 6.0.0

Error in cv.CascadeClassifier (line 33)
            this.id = CascadeClassifier_(filename);

Error in facedetect (line 10)
classifier = cv.CascadeClassifier(xml_file);

@kyamagu
Copy link
Owner

kyamagu commented May 9, 2015

@haipz mexopencv is not compatible with Mathworks CV toolbox by default. To workaround, first find conflicting binaries with otool -L command and add them to DYLD_INSERT_LIBRARIES variable when launching Matlab (See README). The following might give you a sufficient command to launch matlab.

echo DYLD_INSERT_LIBRARIES=`pkg-config --libs opencv | grep -E -o "/.*\.(so|dylib)" | sed "s/ /:/g"` matlab

@haipz
Copy link

haipz commented May 10, 2015

Sorry, I don't know how to do exactly. There are logs:

echo DYLD_INSERT_LIBRARIES=`pkg-config --libs opencv | grep -E -o "/.*\.(so|dylib)" | sed "s/ /:/g"` matlab
DYLD_INSERT_LIBRARIES= matlab
echo $DYLD_INSERT_LIBRARIES=`pkg-config --libs opencv | grep -E -o "/.*\.(so|dylib)" | sed "s/ /:/g"` matlab
/usr/local/lib/libtiff.5.dylib= matlab

@kyamagu
Copy link
Owner

kyamagu commented May 10, 2015

@haipz Your empty result is simply indicating your pkg-config is not correctly returning your own OpenCV path. Check back to your environment and fix PKG_CONFIG_PATH. If the path is correctly set up, the following command would show you how to launch matlab.

echo DYLD_INSERT_LIBRARIES=`pkg-config --libs opencv | grep -o -E "/[^ ]*\.(so|dylib)" | xargs echo | sed "s/ /:/g"` /Applications/MATLAB_R2014b.app/bin/matlab

For example, the above returns

DYLD_INSERT_LIBRARIES=/usr/local/Cellar/opencv/2.4.9/lib/libopencv_calib3d.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_contrib.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_core.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_features2d.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_flann.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_gpu.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_highgui.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_imgproc.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_legacy.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_ml.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_nonfree.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_objdetect.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_ocl.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_photo.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_stitching.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_superres.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_video.dylib:/usr/local/Cellar/opencv/2.4.9/lib/libopencv_videostab.dylib /Applications/MATLAB_R2014b.app/bin/matlab

Note that the above will be different depending on the environment (i.e., version).

Alternative is to move libopencv_*.dylib in Matlab's internal path somewhere else. In OS X, these conflicting libraries are at /Applications/MATLAB_R2014b.app/bin/maci64/.

@haipz
Copy link

haipz commented May 10, 2015

@kyamagu Thank you for answering.
I check my pkg-config by using:

pkg-config --libs opencv

and get the correct result:

-L/usr/local/Cellar/opencv/2.4.11/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab

this seems right. After that I try the code you gave me, and the results is:

NO WORK: echo DYLD_INSERT_LIBRARIES=`pkg-config --libs opencv | grep -o -E "/[^ ]*\.(so|dylib)" | xargs echo | sed "s/ /:/g"` /Applications/MATLAB_R2014b.app/bin/matlab

WORK: echo DYLD_INSERT_LIBRARIES=`pkg-config --libs opencv` /Applications/MATLAB_R2014b.app/bin/matlab

NO WROK: echo DYLD_INSERT_LIBRARIES=`grep -o -E "/[^ ]*\.(so|dylib)" | xargs echo | sed "s/ /:/g"` /Applications/MATLAB_R2014b.app/bin/matlab

NO WROK: echo DYLD_INSERT_LIBRARIES=`grep -o -E "/[^ ]*\.(so|dylib)"` /Applications/MATLAB_R2014b.app/bin/matlab

NO WROK: echo DYLD_INSERT_LIBRARIES=`xargs echo` /Applications/MATLAB_R2014b.app/bin/matlab

NO WROK: echo DYLD_INSERT_LIBRARIES=`sed "s/ /:/g"` /Applications/MATLAB_R2014b.app/bin/matlab

The only work one respond:

DYLD_INSERT_LIBRARIES=-L/usr/local/Cellar/opencv/2.4.11/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab /Applications/MATLAB_R2014b.app/bin/matlab

And I run the result got this:

zsh: command not found: -lopencv_calib3d

@kyamagu
Copy link
Owner

kyamagu commented May 10, 2015

@haipz Okay, then you can construct a launcher command by manually specifying all the dependent dylibs, like

DYLD_INSERT_LIBRARIES=/usr/local/Cellar/opencv/2.4.11/lib/libopencv_calib3d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_contrib.dylib:... /Applications/MATLAB_R2014b.app/bin/matlab

Note that you must list all the dependencies above (...).

@haipz
Copy link

haipz commented May 10, 2015

@kyamagu I run:

DYLD_INSERT_LIBRARIES=/usr/local/Cellar/opencv/2.4.11/lib/libopencv_calib3d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_contrib.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_core.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_features2d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_flann.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_gpu.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_imgproc.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_legacy.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_ml.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_nonfree.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_objdetect.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_ocl.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_photo.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_stitching.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_superres.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_video.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_videostab.dylib /Applications/MATLAB_R2014b.app/bin/matlab

and here returns a new error:

dyld: Library not loaded: /usr/local/lib/libImath-2_1.11.dylib
  Referenced from: /usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib
  Reason: image not found
zsh: trace trap  DYLD_INSERT_LIBRARIES= /Applications/MATLAB_R2014b.app/bin/matlab

@kyamagu
Copy link
Owner

kyamagu commented May 10, 2015

@haipz I suspect this issue.

@haipz
Copy link

haipz commented May 10, 2015

@kyamagu Before I submit my comment, I have read this issue.

brew switch ilmbase 2.1.0
Error: ilmbase does not have a version "2.1.0" in the Cellar.
Versions available: 2.2.0

I don't have version 2.1.0 in the Cellar. I try to install homebrew-versions to find the older version, but homebrew-versions isn't include ilmbase 2.1.0.

UPDATE

I solve the version problem, I download ilmbase-2.1.0.yosemite.bottle.tar.gz from network, then unzip it and copy all the file to /usr/local/Cellar/ilmbase/. After that I success to switch version:

brew switch ilmbase 2.1.0
Cleaning /usr/local/Cellar/ilmbase/2.1.0
Cleaning /usr/local/Cellar/ilmbase/2.2.0
73 links created for /usr/local/Cellar/ilmbase/2.1.0

So far, I got new issue:

DYLD_INSERT_LIBRARIES=/usr/local/Cellar/opencv/2.4.11/lib/libopencv_calib3d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_contrib.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_core.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_features2d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_flann.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_gpu.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_imgproc.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_legacy.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_ml.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_nonfree.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_objdetect.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_ocl.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_photo.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_stitching.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_superres.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_video.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_videostab.dylib /Applications/MATLAB_R2014b.app/bin/matlab
dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib
  Referenced from: /usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib
  Reason: Incompatible library version: libopencv_highgui.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib
  Referenced from: /usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib
  Reason: Incompatible library version: libopencv_highgui.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib
  Referenced from: /usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib
  Reason: Incompatible library version: libopencv_highgui.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib
  Referenced from: /usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib
  Reason: Incompatible library version: libopencv_highgui.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
zsh: trace trap  DYLD_INSERT_LIBRARIES= /Applications/MATLAB_R2014b.app/bin/matlab

UPDATE AGAIN

I find the solution!!! I add /usr/local/lib/libtiff.5.dylib to DYLD_INSERT_LIBRARIES and it works!
Thank you very much @kyamagu .
FINALLY I success install mexopencv on OS X Yosemite 10.10.3, now my DYLD_INSERT_LIBRARIES in ~/.bash_profile content is:

export DYLD_INSERT_LIBRARIES="/usr/local/lib/libtiff.5.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_calib3d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_contrib.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_core.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_features2d.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_flann.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_gpu.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_highgui.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_imgproc.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_legacy.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_ml.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_nonfree.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_objdetect.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_ocl.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_photo.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_stitching.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_superres.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_video.dylib:/usr/local/Cellar/opencv/2.4.11/lib/libopencv_videostab.dylib"

I hope my comments would be helpful for other people, and I post a article on my own blog 海胖博客 to help Chinese: http://haipz.com/ -> http://haipz.com/blog/i/6492
Thank you again, mexopencv is a really nice work!

@kyamagu
Copy link
Owner

kyamagu commented May 10, 2015

@haipz Great :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants