我试图用CMake在SystemC中构建一个简单的hello世界。
这里是SystemC文件 main.cpp :
#include <systemc.h>
using namespace std;
SC_MODULE (hello_world) {
SC_CTOR (hello_world) {
}
void say_hello() {
cout << "Hello World SystemC" << endl;
}
};
int sc_main(int argc, char* argv[]) {
hello_world hello("HELLO");
hello.say_hello();
return(0);
}
这是CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(SystemCExample)
set (CMAKE_PREFIX_PATH /usr/local/systemc-2.3.2)
include_directories(${CMAKE_PREFIX_PATH}/include)
find_library(systemc systemc ${CMAKE_PREFIX_PATH}/lib-linux64)
link_directories(${CMAKE_PREFIX_PATH}/lib-linux64)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(SystemCExample systemc)
我一直收到错误:
/usr/local/systemc-2.3.2/include/sysc/kernel/sc_ver.h:179:错误:未定义引用`sc_core :: sc_api_version_2_3_2_cxx201103L&lt;&amp; sc_core :: SC_DISABLE_VIRTUAL_BIND_UNDEFINED_&gt; :: sc_api_version_2_3_2_cxx201103L(sc_core: :sc_writer_policy)&#39;
它指向sc_ver.h到行:
api_version_check
(
SC_DEFAULT_WRITER_POLICY
);
当我用另一个简单示例替换main.cpp时,也会出现错误消息。我该如何解决?
答案 0 :(得分:6)
很可能你用C ++ 98构建了SystemC。这是默认的。目前,它要求您在库构建期间和应用程序中使用相同的C ++标准。
以下是使用CMake构建SystemC 2.3.2的步骤
cd /path/to/systemc-2.3.2
mkdir build
cmake ../-DCMAKE_CXX_STANDARD = 11 -DCMAKE_BUILD_TYPE = Debug
cmake --build。
CMake会自动将SystemC库目标导出到用户包注册表:https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#user-package-registry
您可以选择将其安装在某处,阅读CMake手册以了解具体方法。
现在尝试创建示例SystemC项目:
<强>的main.cpp 强>
#include <systemc.h>
SC_MODULE (hello_world) {
SC_CTOR (hello_world)
{
SC_THREAD(say_hello);
}
void say_hello()
{
cout << "Hello World SystemC" << endl;
}
};
int sc_main(int argc, char* argv[])
{
hello_world hello("HELLO");
sc_start();
return (0);
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(test_systemc)
find_package(SystemCLanguage CONFIG REQUIRED)
set (CMAKE_CXX_STANDARD ${SystemC_CXX_STANDARD})
add_executable(test_systemc main.cpp)
target_link_libraries(test_systemc SystemC::systemc)
构建,运行,预期输出:
./test_systemc
SystemC 2.3.2 --- Oct 14 2017 19:38:30
Copyright (c) 1996-2017 by all Contributors,
ALL RIGHTS RESERVED
Hello World SystemC