Jump to content

SystemC 2.3.0 with main()


knhan930

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.

Link to comment
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

Link to comment
Share on other sites

  • 6 years later...

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.

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...