You can download a simple example of using C++ inside a CSIM model from: HelloW.sim
(Right-click to Save-As) or HelloW.zip.
You can build and run such C++ models using the methods below:
(The example commands below are for Linux.
They will be very similar for other OS's.
Just adjust according to the default compile setting for your platform.)
- Command-Line Methods:
(As always when doing anything with CSIM, be sure to "source {path}/csim/setup"
before using these methods.)
- CL-Method 1: (- Give your own compile in a separate step.)
- Build w/CSIM and compile separately:
csim -nocomp HelloW.sim
g++ -g out.c $CSIM_ROOT/tools/$CSIM_MTYPE/clsubs_cpp_2.xx.o -lm -lpthread -o sim.exe
(Where 2.xx is set to match your glibc version.)
- Run:
./sim.exe -batch
- CL-Method 2: (- Set up tools to build+compile in one step.)
- Adjust your settings:
export CSIM_CL_COMPILER="g++ -g out.c $CSIM_ROOT/tools/$CSIM_MTYPE/clsubs_cpp_2.xx.o \ -lm -lpthread"
- Build with CSIM in one step:
csim -nongraphical HelloW.sim
- Run:
./sim.exe -batch
- GUI-based Methods:
- GUI-Method:
- Adjust your compiler setting:
gedit $CSIM_ROOT/tools/setup.sh
{
Under the Linux section, change CSIM_C_COMPILER line to:
export CSIM_C_COMPILER="g++ -g -DUSING_GTK out.c \
$CSIM_ROOT/tools/$CSIM_MTYPE/grsubs_gtk_cpp_$LIBC_VERSION.o \
`pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -lm -lpthread"
}
(Or otherwise set your "CSIM_C_COMPILER" environment variable this way.)
- Then Build and Run as normal from the GUI.
(Start the CSIM GUI and click "Tools / Build" and "Tools / Run Sim".)
|
Summary:
- What did we change ?
- Change "gcc" to "g++".
- Add "_cpp_" to the simulator's kernel-object file name.
(For the textual-simulator, change:
"clsubs_2.xx.o" to "clsubs_cpp_2.xx.o"
For the graphical-simulator, change:
"grsubs_2.xx.o" to "grsubs_cpp_2.xx.o"
)
|
|
(CSIM Home Page.)
(Questions, Comments, & Suggestions: admin@csim.com)
|