Skip to content

Instantly share code, notes, and snippets.

@bagheriali2001
Last active March 16, 2024 23:56
Show Gist options
  • Save bagheriali2001/0736fabf7da95fb02bbe6777d53fabf7 to your computer and use it in GitHub Desktop.
Save bagheriali2001/0736fabf7da95fb02bbe6777d53fabf7 to your computer and use it in GitHub Desktop.
How to Install SystemC in Linux (Ubuntu, Debian, ...)

Installing SystemC library in linux

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.

Table of contents

Manual installation

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.

Installing dependencies

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

Downloading systemc and installing it

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

Adding installation location to environment variables

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.

Install using installation script

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 

Compile using systemc

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 ).

# Created by : Ali Bagheri
# GitHub page: https://github.com/bagheriali2001
##### EDIT BELOW THIS LINE #####
## define variables
echo -e "\e[32mDefine variables\e[0m"
SYSTEMC_DOWNLOAD_URL="http://accellera.org/images/downloads/standards/systemc/systemc-2.3.3.tar.gz"
echo -e "\e[32m SYSTEMC_DOWNLOAD_URL = $SYSTEMC_DOWNLOAD_URL\e[0m"
SYSTEMC_FILE_NAME="systemc-2.3.3.tar.gz"
echo -e "\e[32m SYSTEMC_FILE_NAME = $SYSTEMC_FILE_NAME\e[0m"
SYSTEMC_EXTRACTED_FOLDER_NAME="systemc-2.3.3"
echo -e "\e[32m SYSTEMC_EXTRACTED_FOLDER_NAME = $SYSTEMC_EXTRACTED_FOLDER_NAME\e[0m"
SYSTEMC_INSTALLATION_DIRECTORY="$HOME"
echo -e "\e[32m SYSTEMC_INSTALLATION_DIRECTORY = $SYSTEMC_INSTALLATION_DIRECTORY\e[0m"
##### EDIT ABOVE THIS LINE #####
##### DO NOT EDIT BELOW THIS LINE #####
## installing dependencies
echo -e "\e[32mRunning: sudo apt-get update\e[0m"
sudo apt-get update
echo -e "\e[32mRunning: sudo apt install gcc build-essential -y\e[0m"
sudo apt install gcc build-essential -y
## moving to SYSTEMC_INSTALLATION_DIRECTORY
echo -e "\e[32mRunning: cd $SYSTEMC_INSTALLATION_DIRECTORY\e[0m"
cd $SYSTEMC_INSTALLATION_DIRECTORY
## downloading and extracting systemc
echo -e "\e[32mRunning: wget $SYSTEMC_DOWNLOAD_URL\e[0m"
wget $SYSTEMC_DOWNLOAD_URL
echo -e "\e[32mRunning: mkdir $SYSTEMC_EXTRACTED_FOLDER_NAME\e[0m"
mkdir $SYSTEMC_EXTRACTED_FOLDER_NAME
echo -e "\e[32mRunning: tar -xzf $SYSTEMC_FILE_NAME -C $SYSTEMC_EXTRACTED_FOLDER_NAME --strip-components=1\e[0m"
tar -xzf $SYSTEMC_FILE_NAME -C $SYSTEMC_EXTRACTED_FOLDER_NAME --strip-components=1
## installing systemc
echo -e "\e[32mRunning: cd $SYSTEMC_EXTRACTED_FOLDER_NAME\e[0m"
cd $SYSTEMC_EXTRACTED_FOLDER_NAME
echo -e "\e[32mRunning: mkdir objdir\e[0m"
mkdir objdir
echo -e "\e[32mRunning: cd objdir\e[0m"
cd objdir
echo -e "\e[32mRunning: export CXX=g++\e[0m"
export CXX=g++
echo -e "\e[32mRunning: ../configure\e[0m"
../configure
echo -e "\e[32mRunning: make\e[0m"
make
echo -e "\e[32mRunning: make install\e[0m"
make install
echo -e "\e[32mRunning: cd ..\e[0m"
cd ..
echo -e "\e[32mRunning: rm -rf objdir\e[0m"
rm -rf objdir
## adding systemc path to bashrc
echo -e "\e[32mRunning: echo "# SystemC Install path" >> ~/.bashrc\e[0m"
echo "# SystemC Install path" >> ~/.bashrc
echo -e "\e[32mRunning: echo "export SYSTEMC_HOME=$SYSTEMC_INSTALLATION_DIRECTORY/$SYSTEMC_EXTRACTED_FOLDER_NAME" >> ~/.bashrc\e[0m"
echo "export SYSTEMC_HOME=$SYSTEMC_INSTALLATION_DIRECTORY/$SYSTEMC_EXTRACTED_FOLDER_NAME" >> ~/.bashrc
if [ -z "$LD_LIBRARY_PATH" ]; then
echo -e "\e[32mRunning: echo "export LD_LIBRARY_PATH=$SYSTEMC_HOME/lib-linux64" >> ~/.bashrc\e[0m"
echo "export LD_LIBRARY_PATH=$SYSTEMC_HOME/lib-linux64" >> ~/.bashrc
else
echo -e "\e[32mRunning: echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SYSTEMC_HOME/lib-linux64" >> ~/.bashrc\e[0m"
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SYSTEMC_HOME/lib-linux64" >> ~/.bashrc
fi
echo -e "\e[32mSystemC installation is done successfully\e[0m"
echo -e "\e[34m\e[1mCreated by Ali Bagheri\e[0m"
echo -e "\e[34m\e[1mGitHub page: https://github.com/bagheriali2001\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment