Search code examples
c++matlabsimulink

S-Function with c++. Build error


I'm a newbie in MATLAB. I am trying to build my modell with an example for S-Function from the matlab help. This is the sfun_counter_cpp.cpp. The source code is available in "matlabroot/simulink/src/sfun_counter_cpp.cpp" or on http://www-rohan.sdsu.edu/doc/matlab/toolbox/simulink/sfg/sfun_c++2.html.

First I build C++ S-function with the "mex" command as described here: http://www.mathworks.de/de/help/simulink/sfg/building-c-s-functions.html. The build is successful and the sfun_counter_cpp.mexw32 is created. After that I create an S-Function block that provides access to sfun_counter_cpp from my block diagram, click "Incremental build" and get an error message "OPUS MAKE: Don't know how to make 'sfun_counter_cpp.cppm50'. Stop."

*** Found User-Code File TestModell_usr.c from 05-Jul-2013 15:38:59
*** Found User Makefile TestModell_usr.mk from 05-Jul-2013 15:38:59
*** Optional User Variable Description File TestModell_usr.trc not available
.
### Processing Template Makefile: C:\dSPACE\matlab\rti1005\m\rti1005.tmf
### TestModell.mk which is generated from C:\dSPACE\matlab\rti1005\m\rti1005.tmf is up to date
### Building TestModell: dsmake -f TestModell.mk  GENERATE_REPORT=0 EXTMODE_STATIC_ALLOC=0 TMW_EXTMODE_TESTING=0 EXTMODE_STATIC_ALLOC_SIZE=1000000 EXTMODE_TRANSPORT=0

BUILDING APPLICATION "TestModell" (Multiple Timer Task Mode) 

WORK  DIRECTORY "c:\MyTest" 
BUILD DIRECTORY "c:\MyTest\TestModell_rti1005" 
TARGET COMPILER "C:\PPCTools37"  

COMPILING  "TestModell.c"  
COMPILING  "TestModell_data.c"  
COMPILING  "TestModell_trc_ptr.c"  
COMPILING  "rtGetInf.c"  
COMPILING  "rtGetNaN.c"  
COMPILING  "C:\PROGRA~2\MATLAB~1\rtw\c\src\rt_matrx.c"  
COMPILING  "rt_nonfinite.c"  
COMPILING  "C:\dSPACE\MATLAB\RTI1005\C\rt_printf.c"  
COMPILING  "C:\dSPACE\MATLAB\RTI1005\C\rti_sim_engine.c"  
OPUS MAKE: Don't know how to make 'sfun_counter_cpp.cppm50'. Stop. 
----------------------------------------------------------------------
*** Errors occurred during make process.
*** Inspect MATLAB Command Window for details.
*** Aborting RTI build procedure for model TestModell.
----------------------------------------------------------------------
*** Stopped RTI build procedure for model: TestModell.
----------------------------------------------------------------------

Solution

  • The problem is solved. I set

    USER_BUILD_CPP_APPL = ON

    and

    USER_SRCS =

    USER_SRCS = sfun_counter_cpp.cpp produces an error

    < lnkppc > (E) #A0307-D Symbol: sfun_counter_cpp in file: sfun_counter_cpp.cppm50 already defined in file: sfun_counter_cpp.cppm50