How To Build SystemC Compile Environment

Table of Content

I started learning SystemC yesterday, for I found that it is too difficult to understand ArchC if I don't study SystemC first. Thankfully I still remember all fundamental grammars of C++, so I could just focus on the different ways of hardware description between SystemC and Verilog. The book I am reading is SystemC片上系统设计-陈曦,徐宁仪. If Verilog is not new to you, you could start reading this book from the last chapter, where a comparison between Verilog and SystemC has been given in details. However, the purpose of this article is just to tell you how to build a SystemC compile environment on your Linux/ Windows desktop.

I. Prepare Resources

First of all, you need to visit the homepage of SystemC.org, click on DOWNLOADS, then choose Accellera Standards. Find SystemC, click on it and go to Current Release, select the newest version (normally named as systemc-x.x.x). When you click on the download version, a sign up page may pop up, just fill the form and proceed. When asked to choose the tar file type, I recommend you to pick zip type.

II. Install SystemC To Desktop

After downloading the tar file, you need to decide where to build your compile environment.

For Linux desktop, I recommend you to use home directory.

Whereas for Windows desktop, I recommend you to install a simple Cygwin platform, and then build your compile environment at the home directory of it.

So anyway, go to the home directory of your platform, unzip the tar file by the following commands.

[source lang="bash"]
cd ~
unzip systemc-x.x.x.zip
[/source]

When the uncompression is done, open ~/systemc-x.x.x/src/sysc/utils/sc_utils_ids.cpp with your favourate text editor (e.g Vim/ Emacs), make sure the following lines are there. If you are using any build version after systemc-2.3.1, these lines should be there already. Should you find they are not there, add them by hand, save the file and quit.

[source lang="cpp"]
#include <cstdlib>
#include <cstring>
[/source]

Next you need to create two directories under home directory, one can be named as bin, the other can be named as systemc (Of course you can give them other names, but I will continue explanation using these two names in this article). You can finish these by the following commands.

[source lang="bash"]
cd ~
mkdir bin
mkdir systemc
[/source]

Then you need to enter the bin directory, where you can configure the installation mode by running a script named configure. When you run the script, you need to input the target installation directory after argument prefix -prefix. In this article, we are going to install the build environment at the newly created ~/systemc directory. Please note that when you fill in the target directory, the ending slash '/' must be omitted. Because that the script will add a slash to this argument, if the ending slash exists, the final string will become '/home/user/systemc//' and thus the script will prompt an error. You can refer to the following commands to finish these steps.

[source lang="bash"]
cd bin
../configure -prefix=/home/user/systemc
[/source]

配置完毕后就可以用make生成安装文件,安装文件生成完毕就可以用make install开始安装。注意,无论是make还是make install都是在bin目录下进行,有的网上教程说此时需要回到上层目录systemc-x.x.x是错误的。

[source lang="bash"]
make
make install
[/source]

到这里就安装完毕了。如果你进入根目录的systemc目录下看到include和lib-xxx就对了。这里的lib名称跟你的系统有关,本文使用的是Cygwin64位环境,所以产生的是lib-cygwin64。这2个目录名称一定要记下来,之后有用。

另外,网上有的教程说安装前要改环境变量啦,安全后也要去改环境变量啦,改profile啦,其实我在Linux和Cygwin都进行了测试,其实配合Makefile脚本的话,这些都可以不改的。

III. Write Makefile Script

随便新建一个目录测试一下SystemC环境吧。

首先建立一个Makefile文件,然后打开进行编辑。

[source lang="bash"]
cd ~
mkdir test
cd test
vi Makefile
[/source]

Adhere, I'd like to share my makefile script written for my Cygwin platform. You can refer to it and write your own script base on your platform.

[source lang="perl"]
#=====================================================================
# Copyright (c) 2015 By Kellen.Wang
# mail@kellen.wang, All Rights Reserved
#=====================================================================
# config
proj_top = top
proj_module = helloworld.*

# settings
sc_dir = ${SYSTEMC_HOME}
sc_inc = ${sc_dir}/include
sc_lib = ${sc_dir}/lib-cygwin64
sc_arg = -I ${sc_inc} -L ${sc_lib} -lsystemc -Wl,-rpath,${sc_lib}

# commands
${proj_top}: ${proj_module}
g++ ${sc_arg} -o $@ $<

[/source]

关于Makefile的语法就不在这里探讨了,以后开专题讲吧。这里只重点强调SystemC编译需要的几个变量的含义。-I后面跟的是include目录,-L后面跟的是刚才提到过的lib-xxx。lsystemc是告知编译器使用systemc的库进行编译。后面跟的参数是强调lib目录位置的,如果没有的话可能会报一个lib-xxx.so error的错。另外-lsystemc -Wl, -rpath,${sc_lib}这一部分的顺序不能动,大小写也要注意。

另外,前面讲到修改环境变量其实Makefile写好了的话是不必要的。我的Makefile里使用了环境变量${SYSTEMC_HOME},是因为我在环境变量/etc/profile里事先设置好了。如果你不想设置的话也没关系,我的Makefile里sc_dir你改成systemc所在路径就可以了。

IV. Test Helloworld

Now we are going to test our SystemC compile environment with a simple 'helloworld' program. Create two files named as helloworld.h and helloworld.cpp in the test directory.

[source lang="cpp"]
// helloworld.h
#ifndef _HELLO_H
#define _HELLO_H
#include "systemc.h"
SC_MODULE(helloworld) {
SC_CTOR(helloworld){
cout<<"Hello, SystemC!";
};
};
#endif
[/source]

[source lang="cpp"]
// helloworld.cpp
#include "helloworld.h"
int sc_main(int i, char* av[]){
helloworld u_helloworld("u_helloworld");
return 0;
}
[/source]

Now we can try to compile this 'helloworld' program with our makefile script and newly installed SystemC compile environment. Run the following command in the terminal.

[source lang="bash"]
make
[/source]

If everything goes fine, you should be able to see echo as below in the terminal.

[source lang="bash"]
SystemC 2.3.1-Accellera --- Mar 10 2015 22:44:50
Copyright (c) 1996-2014 by all Contributors,
ALL RIGHTS RESERVED
Hello, SystemC!
[/source]

工程师,个人公众号:IF推理同好会,个人微信小游戏:IF迷你侦探
Posts created 32

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top