时间:2016-07-13 13:14:07

标签: c++ hardware fpga systemc asic

我使用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;
                ^~~~

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:10)

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

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

您似乎已经从网页上复制了代码。请记住“”和“”不是一回事。第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");

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