库的 Systemc 错误

Systemc Error with the library

我使用 this 教程安装了 SystemC 库 2.3.1。

我写了这个 hello world 示例:

//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);
}

并使用此命令编译:

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

当我编译代码时,我遇到了库错误:

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;
                ^~~~

我该如何解决这个问题?

您似乎已经从网页上原样复制粘贴了代码。请记住“”和“”不是一回事。第 8 行

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

替换为

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

第 13 行

hello_world hello(“HELLO”);

替换为

hello_world hello("HELLO");

然后再次执行代码。 祝你好运。

std::gets 已在 C++11 中删除(参见 What is gets() equivalent in C11?

如果您使用 C++11 标志(可能带有 g++ 别名)进行构建,则必须在 systemc.h.

中禁用此行

替换

using std::gets;

#if defined(__cplusplus) && (__cplusplus < 201103L)
using std::gets;
#endif

正如guyguy333所述,在新版本中,g++是C++11的别名。 所以添加 -std=c++98 可以解决问题。 编译命令可能喜欢

$ g++ -std=c++98 -lsystemc -pthread main.cpp -o main