Using C++ with CSIM

Bring C++ into the modeling workflow.

Review the C++ integration example. Keep compilation details and code syntax exact as you adapt the approach.

Using C++ with CSIM


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.) 1. 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.) 2. Run:
./sim.exe -batch - CL-Method 2:     (- Set up tools to build+compile in one step.) 1. Adjust your settings:
export CSIM_CL_COMPILER="g++ -g out.c $CSIM_ROOT/tools/$CSIM_MTYPE/clsubs_cpp_2.xx.o \
           -lm -lpthread"
2. Build with CSIM in one step:
csim   -nongraphical   HelloW.sim 3. Run:
./sim.exe -batch - GUI-based Methods: - GUI-Method: 1. 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.)
2. 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 ?

  1. Change "gcc" to "g++".
  2. 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"
       )


ret(CSIM Home Page.)

(Questions, Comments, & Suggestions: admin@csim.com)

This page is an editorial rewrite of source documentation. Historical status, availability, and platform notes are not independently verified for a current release. Technical examples are reference material, not a live simulator.