Thursday, August 25, 2011

Install SystemC 2.2.0 on Ubuntu 11.04

Thanks to these tips from http://archive.pfb.no/2010/10/13/systemc-ubuntu-1010/ and http://noxim.sourceforge.net/pub/Noxim_User_Guide.pdf, I was able to install SystemC on 11.04 Natty Narwhal.


Begin borrowed material


Step 0: Prepare.

Obviously, you need to have a compiler. Do this step in case you haven't done so.

$ sudo apt-get install build-essential

Step 1: Download.

Next: register, and download from http://www.systemc.org using your Web browser then unpack it....but the tgz file has wrong extension. Do these steps to unpack the file:

$ mv systemc-2.2.0.tgz systemc-2.2.0.tar
$ tar xvf systemc-2.2.0.tar

Alternatively, download the file using wget from another site with the correct extension:

$ wget http://panoramis.free.fr/search.systemc.org/?download=sc220/systemc-2.2.0.tgz
$ tar xvfz systemc-2.2.0.tgz

Ooops! Turns out you can't use wget. Copy the URL to your browser location bar, answer a simple a question and the file will be downloaded. In any case, no need to reveal you email for this option!

In any case, create a build directory and enter into it for the following steps:

$ cd systemc-2.2.0
$ sudo mkdir /usr/local/systemc
$ mkdir objdir
$ cd objdir
$ export CXX=g++
$ sudo ../configure --prefix=/usr/local/systemc CPPFLAGS=-fpermissive

Step 2: Patch.

Using new versions of GCC such as GCC 4.4, we will fail to compile because 2 lines of code were left out of systemc-2.2.0/src/sysc/utils/sc_utils_ids.cpp.

Method 1: You can just just open the file and add these includes at the top of the file (after the header comments):

#include "cstdlib"
#include "cstring"
#include "sysc/utils/sc_report.h"

Replace the " signs with less than and greater than signs (because this blog site treats the the pair of characters as HTML tags).

Method 2: You patch it using a prewritten patch file.


$ wget http://www.pfb.no/files/systemc-2.2.0-ubuntu10.10.patch
$ patch -p1 < ../systemc-2.2.0-ubuntu10.10.patch

Method 3: Patch it using sed:

$ sed -i '1 i #include "cstdlib"\n#include "cstring"' ../src/sysc/utils/sc_utils_ids.cpp

Step 3: Compile

$ make
$ sudo make install
$ make check
$ cd ..
$ rm -rf objdir

The command make check is optional. What is does is to compile SystemC source files to see if the files can run. I strongly suggest that you run it.

Step 4: Tell your compiler where to find SystemC

Since we do not install SystemC with a standard location we need to specifically tell the compiler where to look for the libraries. We do this with an environment variable.

$ export SYSTEMC=/usr/local/systemc/
This, however will disappear on the next login. To permanently add it to your environment, alter ~/.profile or ~/.bash_profile if it exists. For system wide changes, edit /etc/environment. (newline with expression: SYSTEMC_HOME=”/usr/local/systemc/“) To compile a systemC program simply use this expression:

$ g++ -I. -I$SYSTEMC/include -L. -L$SYSTEMC/lib-linux -o OUTFILE INPUT.cpp -lsystemc -lm

End borrowed material


I still could not get SystemC installed in Fedora. :(

9 comments:

  1. hi,
    I have completed all the step listed above but I have a problem while compiling,
    could you please help me with this error:


    helloworld.cpp:3:21: fatal error: systemc.h: No such file or directory

    Thanks!
    compilation terminated.

    ReplyDelete
  2. You must be attempting to compile a sample SystemC program. You must give the complete path to the include file when compiling. Check out my other posting on the compiling a SystemC program (as opposed to compiling the SystemC library).

    ReplyDelete
  3. i am facing problem.................

    i have ubuntu 11.10
    problem : not find directory after patch cmd use

    pls help
    GEET KALANI
    ITGEET@GMAIL.COM

    ReplyDelete
    Replies
    1. Not clear what the exact problem is.

      Delete
  4. I am using 10.7.4.
    I used to have systemC working. I _may_ have upgraded my OS and that may have broken it.
    My old Makefile has:

    SYSTEMC_HOME=/Library/SystemC/Current

    So I changed your instructions to:

    ../configure --prefix=/Library/SystemC/Current
    checking build system type...
    configure:1319 error: cannot guess build type; you must specify one

    I don't know what to set build to. Any ideas?

    jr

    ReplyDelete
    Replies
    1. Looks like you're using Mac OS X. I prefer to use the SystemC installer from Logic Poet, and compile using XCode. http://www.logicpoet.com/systemc/

      Delete
  5. Note that now SystemC 2.3.0 is released, the patches and changes above (e.g. -fpermissive, adding headers) are no longer necessary.

    ReplyDelete
  6. True. But some new bugs are introduced. I'm staying with 2.2.0 for the moment.

    ReplyDelete
  7. I need help !
    when I enter this sentence :
    sudo ../configure --prefix=/usr/local/systemc CPPFLAGS=-fpermissive
    It did some instructions then it stops with the following error
    config.status: creating Makefile
    config.status: creating src/Makefile
    config.status: error: cannot find input file: src/Makefile.in
    I tried to make a copy of makefile.in in src but I can't !

    ReplyDelete