参考
官方安装手册 这里官网安装手册有点坑,大家伙多注意一下,官网的注意事项喜欢写在后面,前面巴拉巴拉安装一堆之后,失败了,跑到后面才发现要注意什么注意什么。也可以直接看我后面的步骤。
跑个实例看看
正文
1、背景
背景大概都知道了,Fast-RTPS 作为ros 2的底层通讯架构之一,这里不安装ros2,直接安装测试 Fast-RTPS。
FastDDS的安装有cmake 和 colcon两种安装方式
这里使用cmake 安装,安装的版本为 github版本,cmake 建议升级到3.11以上
使用命令 cmake --version 查看当前 cmake 版本,升级步骤如下
$ wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
$ mv cmake-3.18.0.tar.gz /usr/local/
$ cd /usr/local/
$ tar xf cmake-3.18.0.tar.gz
$ rm -rf cmake-3.18.0.tar.gz
$ cd cmake-3.18.0/
$ sudo ./configure
$ sudo make
$ sudo make install
$ cmake --version
安装 FastRTPS 前,先安装依赖库,如下
sudo apt install libasio-dev libtinyxml2-dev
sudo apt install libssl-dev
sudo apt install cmake g++ python3-pip wget git
//以下的我都没装
//sudo apt install libp11-dev libengine-pkcs11-openssl (可选,只有DDS用到security和PKCS#11 URI时才需要,我没装)
//sudo apt install softhsm2 (可选,我没装,装了libp11-dev才需要)
//sudo usermod -a -G softhsm <user> (可选,我没装,同上)
//sudo apt install libengine-pkcs11-openssl (同上)
//p11-kit list-modules(同上)
//openssl engine pkcs11 -t(同上)
Gtest: 可选,C++单元测试库,我还没装
//git clone https://github.com/google/googletest src/googletest-distribution
然后在 用户目录下,创建文件夹
mkdir ~/Fast-DDS
然后一项一项安装,首先是 Foonathan memory
cd ~/Fast-DDS
git clone https://github.com/eProsima/foonathan_memory_vendor.git
mkdir foonathan_memory_vendor/build
cd foonathan_memory_vendor/build
(先看下文)cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install -DBUILD_SHARED_LIBS=ON
(先看下文)cmake --build . --target install
这里有两个注意事项,如果 按官网如下安装,最后测试时会发现,找不到foonathan的一个库,第二句由于缺少权限导致失败
cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install -DBUILD_SHARED_LIBS=ON
cmake --build . --target install
#将上面修改成如下:
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/ -DBUILD_SHARED_LIBS=ON
sudo cmake --build . --target install
错误如下:
nxchannelone@nx:~/Fast-DDS/Fast-DDS/examples/C++/HelloWorldExample/build$ cmake ..
CMake Error at CMakeLists.txt:29 (find_package):
By not providing "Findfoonathan_memory.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"foonathan_memory", but CMake did not find one.
Could not find a package configuration file provided by "foonathan_memory"
with any of the following names:
foonathan_memoryConfig.cmake
foonathan_memory-config.cmake
Add the installation prefix of "foonathan_memory" to CMAKE_PREFIX_PATH or
set "foonathan_memory_DIR" to a directory containing one of the above
files. If "foonathan_memory" provides a separate development package or
SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/nxchannelone/Fast-DDS/Fast-DDS/examples/C++/HelloWorldExample/build/CMakeFiles/CMakeOutput.log".
然后安装 Fast CDR
cd ~/Fast-DDS
git clone https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR/build
cd Fast-CDR/build
#cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install
#这里依然修改一下路径
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/
sudo cmake --build . --target install
然后安装 Fast DDS,以前的版本应该叫 Fast RTPS,这里和 Fast DDS是一样的
cd ~/Fast-DDS
git clone https://github.com/eProsima/Fast-DDS.git
mkdir Fast-DDS/build
cd Fast-DDS/build
#cmake .. -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install
#这里依然修改一下路径
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/
sudo cmake --build . --target install
然后添加一下环境变量
echo 'export LD_LIBRARY_PATH=/usr/local/lib/' >> ~/.bashrc
然后安装 Fast DDS Gen,由于我也是才刚刚安装,不太知道具体是干啥的,先装
先安装依赖
sudo apt install openjdk-8-jdk
cd ~/Fast-DDS
git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
cd Fast-DDS-Gen
gradle assemble
# 这里没下载 gradle 会失败,可以直接使用中间件,不用下载
./gradlew assemble
然后将环境添加
echo 'export PATH=~/Fast-DDS/Fast-DDS-Gen/scripts:$PATH' >> ~/.bashrc
source ~/.bashrc
在终端 打 fast 按 Tab 键,出现 fastddsgen ,就安装成功了。
最后找到测试文件,进行测试
cd ~/Fast-DDS/Fast-DDS/examples/C++/HelloWorldExample/build
./HelloWorldExample publisher
# 开启另一个终端
./HelloWorldExample subscriber
结果如图