My operating system is Ubuntu 12.04.
0. Checking Your Compilers
First thing first, you will need the tools beforing making stuffs.
- Type "g++ --version" to check if you have g++, if not use "sudo apt-get install g++" to install it first. (Fedora users can use command "yum")
- Type "make --version" to check if you have GNU make, otherwise you know what to do...
1. Downloading SystemC
The first step is to download the source package of SystemC. The official download page is http://www.accellera.org/downloads/standards/systemc. You need to register with your email for accepting the licenses. Currently the newest and stable version of SystemC is 2.3.0.
2. Making SystemC Library Step-by-step
The downloaded tar file are for example located here: ~/Downloads/
cd ~/Downloads/ tar zxvf systemc-2.3.0.tar cd systemc-2.3.0 mkdir objdir cd objdir sudo mkdir /usr/local/systemc/ sudo ../configure --prefix=/usr/local/systemc/ sudo make sudo make install
Here "sudo" is kind of important if you are not root.
3. Compling SystemC Files
Suppose you have already have your SystemC example files here: ~/hello_word/, with file hello.h, and main.cpp.
To compile your SystemC files, use
g++ main.cpp -I$SYSTEMC_HOME/include -L$SYSTEMC_HOME/lib-linux64 -o hello -lsystemc
Of coursee you need to set the environment variable SYSTEMC_HOME first:
export SYSTEMC_HOME=/usr/local/systemc/
or anywhere you actually built it.
In this way your code will be compiled successfully.
4. Running the Executable
The title looks stupid but I still think it is necessary to address it here. Your compilation will be successful but you might face an error when you are trying to run the executable, for example:
./hello: error while loading shared libraries: libsystemc-2.3.0.so: cannot open shared object file: No such file or directory
In this case, you need to set LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/usr/local/systemc/lib-linux
For 64-bit system users, you may set the variable value to:
export LD_LIBRARY_PATH=/usr/local/systemc/lib-linux64
In my case I need to set it to the latter one (To be frank I didn't set it right at the first time). If you are not sure which one you need to set, simply go to that folder, to see you have "lib-linux" or "lib-linux64".
At this stage, you may run your executables without errors.