我使用本教程安装了SystemC库2.3.1。
我写了这个你好世界的例子:
//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;
^~~~
我该如何解决这个问题?
std::gets
已在C++11 中删除(请参阅在 C11 中等效的 gets() 是什么?)
如果使用 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
您似乎已经按原样从网页上复制了代码。请记住"和"不是一回事。在第 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");
然后再次执行代码。祝你好运。