SystemC is a set of C++ libraries, which enables a designer to perform cuncurrent simulation of system level model. It is used for Electronic System Level design and Transaction Level Modelling(TLM). In this article we will discuss the setup of SystemC in an Ubuntu 12.04 Machine and executing our first Hello World! program.
Download SystemC source from Accellera website.
Untar the package using
tar -xzvf systemc-2.3.0.tgz
Change to the top level directory systemc-2.3.0 :
cd systemc-2.3.0
Make a directory systemc230 for installation in your
/usr/local/
path.
sudo mkdir /usr/local/systemc230
Create a directory for object code using
mkdir objdir
Change directory to objdir using
cd objdir
Run configure from your top level directory:
../configure --prefix=/usr/local/systemc230
Do
make
Install by typing command:
sudo make install
You are done with installation of SystemC 2.3.0. This version is packed with TLM package also. Now we can run our first Hello World! program.
Open your favourite text editor and enter the following program:
// All systemc modules should include systemc.h header file
#include <systemc.h>
// Hello_world is module name
SC_MODULE (hello_world) {
SC_CTOR (hello_world) {
// Nothing in constructor
}
void say_hello() {
//Print "Hello World" to the console.
cout << "Hello World.\n";
}
};
// sc_main in top level function like in C++ main
int sc_main(int argc, char* argv[]) {
hello_world hello("HELLO");
// Print the hello world
hello.say_hello();
return(0);
}
Save the file as hello.cpp. Use following command to export a variable SYSTEMC_HOME
.
export SYSTEMC_HOME=/usr/local/systemc230/
Now you can use following command to compile the program:
g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -Wl,-rpath=$SYSTEMC_HOME/lib-linux -o hello hello.cpp -lsystemc -lm
Once the program is compiled type following to run your program
./hello
and you should get output
SystemC 2.3.0-ASI --- Aug 12 2012 09:27:22
Copyright (c) 1996-2012 by all Contributors,
ALL RIGHTS RESERVED
Hello World.
If you get above output, you have successfully completed the setup and run your first SystemC program.
Note: This set of instruction has been tested with Linux Mint 14 which is derivative of Ubuntu Linux. In Ubuntu 12.10, user might need to install g++ before going through these steps.