I am trying to compile developer build for OpenCV (3.0.0), however I cannot configure my system to mex C files. I tried to follow suggestions from stackoverflow and currently I can mex c++ files, but not C ones. What I did was edit mexopts.sh
so that correct SDKROOT
was used, also I changed deployment targets to 10.9
.
My mexopts.sh looks as follows:
#PATCH: MacOSX10.8 // updated manually to 10.9
CC='llvm-gcc'
CXX='llvm-g++'
SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'
#SDKROOT='/'
MACOSX_DEPLOYMENT_TARGET='10.9'
ARCHS='x86_64'
# StorageVersion: 1.0
# CkeyName: GNU C
# CkeyManufacturer: GNU
# CkeyLanguage: C
# CkeyVersion:
CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
CFLAGS="$CFLAGS -fexceptions"
CLIBS="$MLIBS"
COPTIMFLAGS='-O2 -DNDEBUG'
CDEBUGFLAGS='-g'
CLIBS="$CLIBS -lstdc++"
# C++keyName: GNU C++
# C++keyManufacturer: GNU
# C++keyLanguage: C++
# C++keyVersion:
# OLD
#CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
# NEW
CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -std=c++11"
CXXLIBS="$MLIBS -lstdc++"
CXXOPTIMFLAGS='-O2 -DNDEBUG'
CXXDEBUGFLAGS='-g'
Only after I added -std=c++11
to the CXXFLAGS
I was able to compile simple C++ code saved using .cpp
extension. Here is the code for the file I want to compile
#include <math.h>
#include <matrix.h>
#include <mex.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("Hello World!\n");
}
I save it as test.c
and compile. Here is the output i get
mex test.c
In file included from test.c:2: In file included from /Applications/MATLAB_R2012a.app/extern/include/matrix.h:295: /Applications/MATLAB_R2012a.app/extern/include/tmwtypes.h:819:9: error: unknown type name 'char16_t' typedef char16_t CHAR16_T; ^ 1 error generated.
mex: compile of ' "test.c"' failed.
Error using mex (line 206) Unable to complete successfully.
The same error was used when the file was saved as test.cpp
without -std=c++11
in the CXXFLAGS
. I am not experienced in C/C++ but is there some library or flag I need to add to fix the problem? Any suggestions, links would be helpful.
Thank you.
mex -setup
after editing yourmexopts.sh
file? – horchlermexopts.sh
– Gnattuha