Friday, August 26, 2011

Hello World in SystemC

Create two files and run it at the Shell prompt.

1. Edit the CPP file first.

// All systemc modules should include systemc.h header file
 #include "systemc.h"
 // Hello_world is module name
 SC_MODULE (hello_world) {
   SC_CTOR (hello_world) {
     // Nothing in constructor 
   }
   void say_hello() {
     //Print "Hello World" to the console.
     cout << "Hello World.\n";
   }
 };
 
 // sc_main in top level function like in C++ main
 int sc_main(int argc, char* argv[]) {
   hello_world hello("HELLO");
   // Print the hello world
   hello.say_hello();
   return(0);
 }
2. Then create a Makefile. This makefile is reusable for all SystemC projects.
SYSTEMC=/usr/local/systemc
LDFLAGS= -L$(SYSTEMC)/lib-linux -lsystemc
CXXFLAGS=-Wno-deprecated -I$(SYSTEMC)/include -fpermissive

all:
 g++ $(CXXFLAGS) *.cpp $(LDFLAGS)
 ./a.out
3. The command "make" compiles and runs the Hello World program.
$ make
g++ -Wno-deprecated -I/usr/local/systemc/include  *.cpp -L/usr/local/systemc/lib-linux -lsystemc
./a.out

             SystemC 2.2.0 --- Aug 25 2011 10:30:16
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED
Hello World.

8 comments:

  1. U're a savior man ^^ thanks.

    ReplyDelete
  2. Aloha,

    as I am trying to get SysC working on my system, I have tried almost every HelloWorldTutorial there is, also this one.
    But I am getting an error when compiling (from shell, as well as from eclipse). Anyone having an idea?

    error while loading shared libraries: libsystemc-2.3.0.so: cannot open shared object file: No such file or directory
    make: *** [all] Error 127

    ReplyDelete
    Replies
    1. I have the same problem like you. I guess this would be helpful for you. http://www.accellera.org/Discussion_Forums/helpforum/archive/msg?list_name=help_forum&monthdir=201202&msg=msg00003.html

      Thanks,

      Delete
    2. export LD_LIBRARY_PATH=\$HOME/SystemC/include:$LD_LIBRARY_PATH

      Delete
  3. -static flag at compiling did solve the problem.

    ReplyDelete
  4. Looks like you solved your problem. Great.

    ReplyDelete
  5. I think that the best is use export LD_LIBRARY_PATH="completed route to lib-linux":

    export LD_LIBRARY_PATH="begining of route..."/systemc-2.3.0/lib-linux

    if you want know the libraries that use your program, you can use:

    ldd "program_name"

    ReplyDelete
  6. Below is an improved version of this program because the original has problems and is not strictly correct.

    // All systemc modules should include systemc.h header file
    #include
    using namespace sc_core;
     // Hello_world is module name
     SC_MODULE (hello_world) {
       SC_CTOR (hello_world) {
         SC_THREAD(say_hello);
       }
       void say_hello(void) {
         //Print "Hello World" to the console.
         SC_REPORT_INFO("Example","Hello World.\n");
    sc_stop();
       }
     };
      
     // sc_main in top level function like in C++ main
     int sc_main(int argc, char* argv[]) {
       hello_world hello("HELLO");
       // Print the hello world
       sc_start();
       return(0);
    }

    ReplyDelete