This is a toturial to install systemc library in a linux machine. If you are using windows machine and don't have access to a linux machine, I suggest to use WSL.
This section is for manual installation of systemc library. If you want to use a script to install systemc, go to Install using installation script section.
At first you have to install gcc and a package to build the library for you. So run this commands in terminal:
sudo apt-get update
sudo apt install gcc build-essential -y
First you will download a version of systemc, in this tutorial i use version 2.3.3.
Note: You can do this anywhere in your machine, but i recommend to do it in home directory. If not, remember to replace directories with your chosen directory in the rest of commands. You can simply fo to home directory with cd $HOME
command.
Simply download it with this command:
wget http://accellera.org/images/downloads/standards/systemc/systemc-2.3.3.tar.gz
Then you have to extract it using
tar -xvzf systemc-2.3.3.tar.gz
This section that is the installation part is from systemc official github repo. You can read it there if you want to know more about it.
cd systemc-2.3.3
mkdir objdir
cd objdir
export CXX=g++
../configure
make
make install
cd ..
rm -rf objdir
At this step you have to specify the location of installation of systemc for your compiler.
Note: In this step I am assuming you downloaded systemc file in your home directory. if you used another directory, just replace $HOME
in below commands with your chosen directory.
First run this command:
echo $LD_LIBRARY_PATH
If the result was empty run commands below:
echo "# SystemC Install path" >> ~/.bashrc
echo "export SYSTEMC_HOME=$HOME/systemc-2.3.3" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$SYSTEMC_HOME/lib-linux64" >> ~/.bashrc
but if it was not empty run these commands instead:
echo "# SystemC Install path" >> ~/.bashrc
echo "export SYSTEMC_HOME=$HOME/systemc-2.3.3" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SYSTEMC_HOME/lib-linux64" >> ~/.bashrc
Before trying to compile anything, close and open your terminal.
You can install systemc with script attached to this gist too. If you want to change the version of systemc, download link, installation directory or extracted folder name, just simply edit ###define variables
section. ( For version, you have to change the download link too. )
You can download the script with this command:
wget https://gist.githubusercontent.com/bagheriali2001/0736fabf7da95fb02bbe6777d53fabf7/raw/3b55bcbecc568b7a0be8fb7837987d5d364adcfe/systemc_v2.3.3_installation_script.sh
If you want to edit the script, you can do it with nano
with this command:
nano systemc_v2.3.3_installation_script.sh
And exit from nano
with ctrl + x
then y
then press enter
.
Then run it with this command:
bash ./systemc_v2.3.3_installation_script.sh
Now you can compile any file that is using systemc library with g++. For compiling you should use this template command:
g++ -I. -I$SYSTEMC_HOME/include -L. -L$LD_LIBRARY_PATH -lsystemc -lm -o output_file source_file.cpp
Or compile and run with this command:
g++ -I. -I$SYSTEMC_HOME/include -L. -L$LD_LIBRARY_PATH -lsystemc -lm -o output_file source_file.cpp && output_file
Note: if the above compiling commands did not work for you, just replace $SYSTEMC_HOME
with the location of installation folder ( like /home/ubuntu/systemc-2.3.3
) and replace $LD_LIBRARY_PATH
with location of lib-linux64
folder inside installation folder ( like /home/ubuntu/systemc-2.3.3/lib-linux64
).