How can I get started with the [FASTDDS] 03-hello_fastdds tutorial?

更新于
2026-10-10 06:37:15
2阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计467个文字,预计阅读时间需要2分钟。

How can I get started with the [FASTDDS] 03-hello_fastdds tutorial?

直接输出结果:

hello-world-fastdds步骤如下:

1.创建消息.IDL文件,使用fastddsgen生成消息对应的源文件。

2.编译、运行示例程序。

3.创建消息文件://hello_fastdds.I

How can I get started with the [FASTDDS] 03-hello_fastdds tutorial?

hello-world-fastdds

本章我们运行第一个fastdds示例——hello-world-fastdds。步骤如下:

  1. 创建消息.IDL文件
  2. 使用fastddsgen生成消息对应的源文件
  3. 编译、运行示例

创建消息文件

//hello_fastdds.IDL struct hello_world { string name; int counter; };

生成消息对应的源文件

fastddsgen会在命令运行的文件夹下生成文件。

export PATH=${FAST_DDS_ROOT}/Fast-DDS-Gen/scripts:$PATH fastddsgen -example CMake hello_fastdds.IDL

编译运行

修改编译脚本

修改CMake文件,增加相关库的查找路径

# 这三个是必要的,为了找到对应的库,我们将库安装在 $ENV{FAST_DDS_ROOT}/install 下 set(fastcdr_DIR $ENV{FAST_DDS_ROOT}/install/lib/cmake/fastcdr) set(fastrtps_DIR $ENV{FAST_DDS_ROOT}/install/share/fastrtps/cmake) set(foonathan_memory_DIR $ENV{FAST_DDS_ROOT}/install/lib/foonathan_memory/cmake)

编写编译脚本

#!/bin/bash export FAST_DDS_ROOT=~/work/code/third_party/Fast-DDS-GIT export LD_LIBRARY_PATH=${FAST_DDS_ROOT}/install/lib:$LD_LIBRARY_PATH rm build -rf DIR = $PWD mkdir build && cd build && cmake ../ && make -j4 cd $DIR

运行程序

运行程序前,需要指定依赖库的查找路径,命令和运行结果分别如下:

运行发布者

export FAST_DDS_ROOT=~/work/code/third_party/Fast-DDS-GIT export LD_LIBRARY_PATH=${FAST_DDS_ROOT}/install/lib:$LD_LIBRARY_PATH ./hello_fastdds publisher # Starting # hello_world DataWriter created. # hello_world DataWriter waiting for DataReaders. # DataWriter matched.

运行消费者

export FAST_DDS_ROOT=~/work/code/third_party/Fast-DDS-GIT export LD_LIBRARY_PATH=${FAST_DDS_ROOT}/install/lib:$LD_LIBRARY_PATH ./hello_fastdds subscriber # Starting # Waiting for Data, press Enter to stop the DataReader. # Subscriber matched. # Sample received, count=1

本文共计467个文字,预计阅读时间需要2分钟。

How can I get started with the [FASTDDS] 03-hello_fastdds tutorial?

直接输出结果:

hello-world-fastdds步骤如下:

1.创建消息.IDL文件,使用fastddsgen生成消息对应的源文件。

2.编译、运行示例程序。

3.创建消息文件://hello_fastdds.I

How can I get started with the [FASTDDS] 03-hello_fastdds tutorial?

hello-world-fastdds

本章我们运行第一个fastdds示例——hello-world-fastdds。步骤如下:

  1. 创建消息.IDL文件
  2. 使用fastddsgen生成消息对应的源文件
  3. 编译、运行示例

创建消息文件

//hello_fastdds.IDL struct hello_world { string name; int counter; };

生成消息对应的源文件

fastddsgen会在命令运行的文件夹下生成文件。

export PATH=${FAST_DDS_ROOT}/Fast-DDS-Gen/scripts:$PATH fastddsgen -example CMake hello_fastdds.IDL

编译运行

修改编译脚本

修改CMake文件,增加相关库的查找路径

# 这三个是必要的,为了找到对应的库,我们将库安装在 $ENV{FAST_DDS_ROOT}/install 下 set(fastcdr_DIR $ENV{FAST_DDS_ROOT}/install/lib/cmake/fastcdr) set(fastrtps_DIR $ENV{FAST_DDS_ROOT}/install/share/fastrtps/cmake) set(foonathan_memory_DIR $ENV{FAST_DDS_ROOT}/install/lib/foonathan_memory/cmake)

编写编译脚本

#!/bin/bash export FAST_DDS_ROOT=~/work/code/third_party/Fast-DDS-GIT export LD_LIBRARY_PATH=${FAST_DDS_ROOT}/install/lib:$LD_LIBRARY_PATH rm build -rf DIR = $PWD mkdir build && cd build && cmake ../ && make -j4 cd $DIR

运行程序

运行程序前,需要指定依赖库的查找路径,命令和运行结果分别如下:

运行发布者

export FAST_DDS_ROOT=~/work/code/third_party/Fast-DDS-GIT export LD_LIBRARY_PATH=${FAST_DDS_ROOT}/install/lib:$LD_LIBRARY_PATH ./hello_fastdds publisher # Starting # hello_world DataWriter created. # hello_world DataWriter waiting for DataReaders. # DataWriter matched.

运行消费者

export FAST_DDS_ROOT=~/work/code/third_party/Fast-DDS-GIT export LD_LIBRARY_PATH=${FAST_DDS_ROOT}/install/lib:$LD_LIBRARY_PATH ./hello_fastdds subscriber # Starting # Waiting for Data, press Enter to stop the DataReader. # Subscriber matched. # Sample received, count=1