Boost logo

Boost Users :

Subject: [Boost-users] Boost.Statechart and Simulink
From: Derek Ditch (derek.ditch+boost_at_[hidden])
Date: 2008-11-19 22:13:50

I was wondering if there were any known issues with compiling using Matlab's
mex compiler (which in turn uses and links with gcc) and using
Boost.Statechart. When I implemented my statechart, I tested it using a
separate main() file and it works 100%. When I compile using mex into a
Matlab MEX file, I seem to lose the functionality of the event triggers.
 I've tried several things to figure out what is happening, but all I can
ascertain is that if I use the iterators state_begin() and state_end() to
access all internal states, the loop never executes. I tried to dereference
state_begin(), but got a segfault. My initial approach was to use the
state_downcast<>(), but this didn't work in SImulink either. My final
suspicion was that it had something to do with the extern "C" business, but
admittedly, I don't understand the effects of this statement other than how
the symbol appears in the library (i.e. avoiding mangling). I get this same
behavior on OS X 10.5 w/ gcc 4.0.1 as well as on Linux x86_64 with gcc
If anyone wants to have my Simulink model to test, I could send that as

I've attached the following files:

ctrl_machine.[ch]pp - My state machine implementation/declaration.
main.cpp - My test program
air_controller.cpp - The C++ SFunction implementation used in Simulink.

mex uses the following compilation steps with gcc/g++

-> g++-4.2 -c -I/opt/matlab/extern/include -I/opt/matlab/simulink/include
-DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
 -DMX_COMPAT_32 -O -DNDEBUG "ctrl_machine.cpp"

-> g++-4.2 -c -I/opt/matlab/extern/include -I/opt/matlab/simulink/include
-DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
 -DMX_COMPAT_32 -O -DNDEBUG "air_controller.cpp"

-> gcc-4.2 -c -I/opt/matlab/extern/include -I/opt/matlab/simulink/include
-DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC
-fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG

-> g++-4.2 -O -pthread -shared
-Wl,--no-undefined -o "ctrl_machine.mexa64" ctrl_machine.o
air_controller.o mexversion.o -Wl,-rpath-link,/opt/matlab/bin/glnxa64
-L/opt/matlab/bin/glnxa64 -lmx -lmex -lmat -lm -lm


Derek Ditch

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at