使用 CMake 设置 SystemC 项目:对 `sc_core 的未定义引用

2024-06-23

我正在尝试使用 CMake 在 SystemC 中构建一个简单的 hello world。

这是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::sc_api_version_2_3_2_cxx201103L(sc_core::sc_writer _政策)'

它指向 sc_ver.h 行:

api_version_check
(
  SC_DEFAULT_WRITER_POLICY
);

当我用另一个简单的示例替换 main.cpp 时,也会出现错误消息。我该如何修复它?


您很可能已经使用 C++98 构建了 SystemC。这是默认的。目前,它要求您在库构建期间和应用程序中使用相同的 C++ 标准。

以下是使用 CMake 构建 SystemC 2.3.2 的步骤

  1. Download SystemC 2.3.2, unpack, change directory to systemc-2.3.2

    cd /path/to/systemc-2.3.2

  2. Create build directory:

    mkdir 构建

  3. Configure SystemC build with C++11 support. I also recommend to build it in Debug mode, this helps while learning. Later you can switch to Release builds to speed-up simulation

    cmake ../ -DCMAKE_CXX_STANDARD=11 -DCMAKE_BUILD_TYPE=调试

  4. Build

    cmake --build 。

CMake 会自动将 SystemC 库目标导出到用户包注册表:https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#user-package-registry 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 CMake 设置 SystemC 项目:对 `sc_core 的未定义引用 的相关文章

随机推荐