The same model can also be compiled to equivalent C++ code with the following command:
scc -lcpp HelloWorld.des
The following information is displayed in the console:
----- Time spent on compilation: 0.045 (sec) File(s) generated: HelloWorld.cpp ----- Command to compile the source: g++ -o HelloWorld HelloWorld.cpp Command to run the compiled code: ./HelloWorld -----
File HelloWorld.cpp is generated, which can be compiled with G++ (the GNU C++ compiler) with the following command:
g++ -o HelloWorld HelloWorld.cppIn Windows, compiling C++ source code with G++ requires Cygwin.
The HelloWorld executable can be directly executed on the command-line. The result is as following:
Hello World Example ['A'] > e ['B'] > exit
The action code is ignored in this executable.
If the user wants to get a C++ head file, which can be included in other C++ sources, he/she may use the -head command-line parameter. In that case, two files are generated: HelloWorld.h and HelloWorld.cpp. The G++ command to compile this source is not changed.
The -ext parameter can be used to instruct SCC to include support for the action code and guards. However, the Python library is required to compile the generated C++ code, and if the model loads user-defined Python libraries with import statements, those libraries must be in the PYTHONPATH environment variable. For example, to synthesize code for the HelloWorld example with action language support, execute the following command:
scc -lcpp --ext HelloWorld.des
Again, HelloWorld.cpp is generated. The command to compile this C++ source is different and much more complex:
g++ -I/usr/include/python2.2 -L/usr/lib/python2.2/config -Xlinker -export-dynamic \ HelloWorld.cpp -lpython2.2 -lm -ldl -lpthread -lutil -o HelloWorld
(The user may concatenate the two lines with the ending ``'' mark on the first line removed.)
SCC automatically detects the libraries and head files of the Python version that is being used. In the above example, the Python head files are located at /usr/include/python2.2 and the Python libraries are at /usr/lib/python2.2/config. Other command-line parameters for G++ depend on the parameters with which Python itself was compiled. This command-line differs in different systems. If the user does not want to compile the source with the Python that is being used (the Python in which SCC is executed), he/she must modify the paths to the head files and libraries according to another version of Python.
When compiled, HelloWorld is the executable, which yields the following result:
Hello World Example ['A'] > e Hello World! ['B'] > exit
This execution result is exactly the same as the execution result of HelloWorld.py and the simulation result of HelloWorld.des in SVM.