有没有办法为 OpenDDS 生成代码

问题描述

我知道 RTI 有一个代码生成器来创建发布者和订阅者,然后允许您创建 DataReader 和 DataWriter。有没有办法在 OpenDDS 中生成所需的代码?我已经建立了列出要传输的主题的 idl 文件,我在这里看到:https://objectcomputing.com/resources/publications/mnb/code-generation-with-opendds-part-i 提供了生成包装器的说明,但我仍然不明白是否有一种方法可以简单地构建 idl 文件,以便它生成 OpenDDS 架构所需的发布者和订阅文件。例如 RTI 有 rtiddsgen。

当我仅使用 Messenger.idl 构建文件时,出现错误消息:

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - not found
-- Found Threads: TRUE
-- Configuring done
CMake Error at CMakeLists.txt:15 (add_executable):
  Cannot find source file:

    Publisher.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at CMakeLists.txt:22 (add_executable):
  Cannot find source file:

    Subscriber.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at CMakeLists.txt:15 (add_executable):
  No SOURCES given to target: publisher


CMake Error at CMakeLists.txt:22 (add_executable):
  No SOURCES given to target: subscriber

cmake 文件如下所示:


    project(OpenDDS_DevGuide_Messenger CXX)
cmake_minimum_required(VERSION 3.8.2)

find_package(OpenDDS required)

set(CMAKE_CXX_COMPILER ${OPENDDS_COMPILER})

set(opendds_libs
  OpenDDS::Dcps # Core OpenDDS Library
  OpenDDS::InfoRepodiscovery OpenDDS::Tcp # For run_test.pl
  OpenDDS::Rtps OpenDDS::Rtps_Udp # For run_test.pl --rtps
)

# Publisher
add_executable(publisher
  Publisher.cpp
)
OPENDDS_TARGET_SOURCES(publisher Messenger.idl)
target_link_libraries(publisher ${opendds_libs})

# Subscriber
add_executable(subscriber
  Subscriber.cpp
  DataReaderListenerImpl.cpp
)
OPENDDS_TARGET_SOURCES(subscriber Messenger.idl)
target_link_libraries(subscriber ${opendds_libs})

解决方法

是的,OpenDDS 有一个代码生成器,opendds_idl,它是 OpenDDS 的核心组件之一。它可以手动、通过 MPC 或使用 OPENDDS_TARGET_SOURCES 在 CMake 中运行,就像您在此处一样。

该错误是不言自明的。这是来自 Developer's Guide Messenger 示例的 CMakeLists.txt 文件,其中包含 C++ 文件。 CMake 找不到它们。也许您在其他地方复制了 CMakeLists.txt 而没有复制 cpp 文件?如果是这样,您可以将 cpp 文件复制到复制 CMakeLists.txt 的位置。