4

I installed the SystemC library 2.3.1 using this tutorial.

I wrote this hello world example:

//hello.cpp
#include <systemc.h>

SC_MODULE (hello_world) {
  SC_CTOR (hello_world) {
  }

  void say_hello() {
    cout << ”Hello World systemc-2.3.0.\n”;
  }
};

int sc_main(int argc, char* argv[]) {
  hello_world hello(“HELLO”);
  hello.say_hello();
  return(0);
}

and compiled with this command:

export SYSTEMC_HOME=/usr/local/systemc230/
g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -Wl,-rpath=$SYSTEMC_HOME/lib-linux -o hello hello.cpp -lsystemc -lm

When I compile the code, I got a error with the library:

In file included from hello.cpp:1:0:
/usr/local/systemc230/include/systemc.h:118:16: error: ‘std::gets’ has not been declared
     using std::gets;
                ^~~~

How can I solve this?

3 Answers3

12

std::gets has been removed in C++11 (See What is gets() equivalent in C11?)

If you're building using C++11 flag (maybe with a g++ alias), you have to disable this line in systemc.h.

Replace

using std::gets;

with

#if defined(__cplusplus) && (__cplusplus < 201103L)
using std::gets;
#endif
Community
  • 1
  • 1
Guillaume
  • 1,277
  • 8
  • 11
  • With this fix the error is now this: /usr/bin/ld: cannot find -lsystemc collect2: error: ld returned 1 exit status – Álison Venâncio Jul 13 '16 at 14:26
  • 1
    If you're working on a x64 Linux, you have to change g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -Wl,-rpath=$SYSTEMC_HOME/lib-linux -o hello hello.cpp -lsystemc -lm to g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux64 -Wl,-rpath=$SYSTEMC_HOME/lib-linux64 -o hello hello.cpp -lsystemc -lm – Guillaume Jul 13 '16 at 14:31
2

As guyguy333 mentioned, in new versions, g++ is an alias for C++11. so adding -std=c++98 would solve the problem. The compile command may like

$ g++ -std=c++98 -lsystemc -pthread main.cpp -o main
Pazel1374
  • 218
  • 3
  • 14
0

You seem to have copy pased the code from webpage as it is. Please remember “” and "" are not the same thing. On line 8

cout << ”Hello World systemc-2.3.0.\n”;

replace it with

cout << "Hello World systemc-2.3.0.\n";

and on line 13

hello_world hello(“HELLO”);

replace it with

hello_world hello("HELLO");

And then execute the code again. GoodLuck.

rkrara
  • 442
  • 1
  • 6
  • 17