Search code examples
matlabxcode5osx-maverickssimulink

Compiling embedded MATLAB functions in Simulink, Mac OSX 10.9 Mavericks, Xcode 5, MATLAB 2012b


After I updated to the latest OSX Mavericks, I've had some issues compiling simple MATLAB function blocks in Simulink, like the diagram and the attached code below. Simple Simulink diagram

function y = fcn(t)
   %#codegen
   %Simple MATLAB .m function to be compiled with the diagram

y = sin(t)+cos(t);

I had the same problem under OSX 10.8 Mountain Lion, but I was able to solve the problem by downloading a Mathworks patch and following the instructions on this site.

With the new OS and having upgraded to Xcode 5, I followed the instructions in this post to change the compiler and SDK info in my mexopts.sh file from

#PATCH: MacOSX10.8
        CC='llvm-gcc-4.2'
        CXX='llvm-g++-4.2'
        SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/'

        MACOSX_DEPLOYMENT_TARGET='10.8'
        ARCHS='x86_64'

to

#PATCH: MacOSX10.9
        CC='llvm-gcc'
        CXX='llvm-g++'
        SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'

        MACOSX_DEPLOYMENT_TARGET='10.9'
        ARCHS='x86_64'

After running mex -setupand restarting MATLAB, I get the following error when trying to run a Simulink model with a function block (the behavior is the same for all models with these blocks):

Making simulation target "mextest_sfun", ... 


/Applications/MATLAB.app/bin/mex -c -O   -DMATLAB_MEX_FILE 
-I/Applications/MATLAB.app/toolbox/stateflow/stateflow/../../../simulink/include 
-I/Applications/MATLAB.app/toolbox/stateflow/stateflow/../../../extern/include 
-I/Applications/MATLAB.app/stateflow/c/mex/include 
-I/Applications/MATLAB.app/stateflow/c/debugger/include   mextest_sfun.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

/Applications/MATLAB.app/bin/mex -c -O   -DMATLAB_MEX_FILE 
-I/Applications/MATLAB.app/toolbox/stateflow/stateflow/../../../simulink/include 
-I/Applications/MATLAB.app/toolbox/stateflow/stateflow/../../../extern/include 
-I/Applications/MATLAB.app/stateflow/c/mex/include 
-I/Applications/MATLAB.app/stateflow/c/debugger/include   mextest_sfun_registry.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

/Applications/MATLAB.app/bin/mex -c -O   -DMATLAB_MEX_FILE 
-I/Applications/MATLAB.app/toolbox/stateflow/stateflow/../../../simulink/include 
-I/Applications/MATLAB.app/toolbox/stateflow/stateflow/../../../extern/include 
-I/Applications/MATLAB.app/stateflow/c/mex/include 
-I/Applications/MATLAB.app/stateflow/c/debugger/include   c2_mextest.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

/Applications/MATLAB.app/bin/mex -silent LDFLAGS="\$LDFLAGS " -output mextest_sfun.mexmaci64      mextest_sfun.o mextest_sfun_registry.o c2_mextest.o      /Applications/MATLAB.app/stateflow/c/mex/lib/maci64/sfc_mex.a /Applications/MATLAB.app/stateflow/c/debugger/lib/maci64/sfc_debug.a -L/Applications/MATLAB.app/bin/maci64 -lfixedpoint -lut -lmwmathutil -lemlrt -lmwblascompat32  -L/Applications/MATLAB.app/bin/maci64 -lippmwipt
Undefined symbols for architecture x86_64:
  "sf_debug_api(int, mxArray_tag**, int, mxArray_tag const**)", referenced from:
  _mexFunction in mextest_sfun_registry.o
"_callCustomFcn", referenced from:
  _mdl_start_processing in sfc_mex.a(sfc_sf.o)
  _mdlTerminate in sfc_mex.a(sfc_sf.o)
"_sf_machine_global_initializer", referenced from:
  _mdl_start_processing in sfc_mex.a(sfc_sf.o)
 "_sf_machine_global_method_dispatcher", referenced from:
  _call_sf_machine_global_method_dispatcher in sfc_mex.a(sfc_sf.o)
"_sf_machine_global_terminator", referenced from:
  _mdlTerminate in sfc_mex.a(sfc_sf.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 ' "mextest_sfun.mexmaci64"' failed.

gmake: *** [mextest_sfun.mexmaci64] Error 1

I'm thinking it's the Undefined symbols for architecture x86_64 that is the key message here, but I really do not know. Have anyone had the same issues, or do anyone have a solution to this? Any help would be much appreciated. Thanks!


Solution

  • After searching the internet and waiting for answers on this forum with no results, the solution to my problem eventually became upgrading to MATLAB 2013a.

    In addition, a little modification to the mexopts.shfile was needed. Just replace all instances of 10.7 to either 10.8 or 10.9. Both of these worked for me, but I ended up replacing it with 10.9 as I'm running Mavericks.

    The "official" solution to this can be found on this site.