Jump to content
knhan930

SystemC 2.3.0 with main()

Recommended Posts

Another issue I have is that I have a simple C++ code that uses only SystemC datatypes from SystemC library like below.

#include "systemc.h"


int main() {
 sc_uint<8> a, b;
 sc_uint<9> z;

 z = a + b;
}

It’s working with SystemC 2.2.0, but there is a link error with SystemC 2.3.0. I used the general compile command with GCC 4.2.2:

% g++ -I$SYSTEMC/include test.cpp –L$SYSTEMC/lib-linux64 -lsystemc
…/systemc-2.3.0/lib-linux64/libsystemc.so: undefined reference to `sc_main' collect2: ld returned 1 exit status

I wonder if SystemC 2.3.0 disables to use main() at all, which was ok with SystemC 2.2.0. It may cause the compatibility issue, so I would like to know how to remove the link error. Thank you.

Share this post


Link to post
Share on other sites

% g++ -I$SYSTEMC/include test.cpp –L$SYSTEMC/lib-linux64 -lsystemc
…/systemc-2.3.0/lib-linux64/libsystemc.so: undefined reference to `sc_main' collect2: ld returned 1 exit status

If you look at the error message more closely, the problem is not caused by the existence of your "main" function, but by the missing sc_main function. The main reason for this is the preferred use of the dynamic library since SystemC 2.3.0. The dynamic libraries needs the sc_main symbol to be present, as you cannot decide during the (dynamic) linking step, if this function is actually called or not.

I wonder if SystemC 2.3.0 disables to use main() at all, which was ok with SystemC 2.2.0. It may cause the compatibility issue, so I would like to know how to remove the link error. Thank you.

Two solutions are possible

  • link against the static library libsystemc.a (e.g. by moving libsystemc.so out of the way)
  • add an (empty) sc_main

Greetings from Oldenburg,

Philipp

Share this post


Link to post
Share on other sites

I've tried link against the static library libsystemc.a, I got error below:

/home/taog/tools/systemc-2.3.1/lib-linux64//libsystemc.a(sc_main_main.o): In function `sc_elab_and_sim':
/home/taog/tools_src/systemc-2.3.1a/objdir/src/sysc/kernel/../../../../src/sysc/kernel/sc_main_main.cpp:84: undefined reference to `sc_main'

I need to pack a library based on SystemC, adding a empty sc_main in a library is weld.

Share this post


Link to post
Share on other sites
37 minutes ago, taog said:

I've tried link against the static library libsystemc.a, I got error below:

/home/taog/tools/systemc-2.3.1/lib-linux64//libsystemc.a(sc_main_main.o): In function `sc_elab_and_sim':
/home/taog/tools_src/systemc-2.3.1a/objdir/src/sysc/kernel/../../../../src/sysc/kernel/sc_main_main.cpp:84: undefined reference to `sc_main'

I need to pack a library based on SystemC, adding a empty sc_main in a library is weld.

Either you as the library author or the user of that library will need to provide at least an empty implementation of sc_main() to satisfy the linker. There is no way around it. I would like to also suggest that you update your SystemC installation to the latest version 2.3.3.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×