FastDDS 安裝過程的坑🕳坑🕳坑🕳坑🕳坑🕳坑🕳


第一次遇到這么坎坷的安裝過程,幾乎沒有一步能順利走下去,不論選擇了哪條路😂

條條大路走不通之 Colcon 方式安裝

FastDDS Github 上找到如下安裝步驟(Colcon 方式):

pip install -U colcon-common-extensions vcstool
mkdir fastdds_ws
cd fastdds_ws
wget https://raw.githubusercontent.com/eProsima/Fast-DDS/master/fastrtps.repos
mkdir src
vcs import src < fastrtps.repos

🕳 1:raw.githubusercontent.com 無法訪問

  1. 修改 hosts 文件
  2. 替換為鏡像站:把 githubusercontent.com 全部替換成 raw.fastgit.org
    例如
    wget https://raw.githubusercontent.com/eProsima/Fast-DDS/master/fastrtps.repos
    
    替換為
    wget https://raw.fastgit.org/eProsima/Fast-DDS/master/fastrtps.repos
    

我還試過 gitee 和 cnpmjs.org 鏡像站,倉庫不全,有的提示找不到

🕳 2:github 連接速度慢/無法訪問

使用鏡像站點。

git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/"

或者

git config --global url."https://hub.fastgit.org/".insteadOf "https://github.com/"

🕳 3:Command 'vcs' not found

vcs import src < fastrtps.repos

Command 'vcs' not found, did you mean:
...
Try: sudo apt install <deb name>

原因:pip install 可能把 vcs 安裝到了 ~/.local/bin
解決辦法:修改 PATH 變量

PATH=$PATH:~/.local/bin

搞定!(高興得太早😂)

🕳 4:colcon 報錯

ERROR:colcon.colcon_core.entry_point:Exception loading extension 'colcon_core.environment_variable.defaults': (pyparsing 3.0.5 (/home/zijian/.local/lib/python3.8/site-packages), Requirement.parse('pyparsing<3,>=2.0.2'), {'packaging'})

你厲害,你厲害,我放棄。

條條大路走不通之 Linux 源碼方式安裝

安裝序列化庫 CDR

$ git clone https://github.com/eProsima/Fast-CDR.git
$ mkdir Fast-CDR/build && cd Fast-CDR/build
$ cmake ..
$ cmake --build . --target install

如果最后一步提示沒有權限,sudo 一下即可

安裝 foonathan 分配器

$ git clone https://github.com/eProsima/foonathan_memory_vendor.git
$ cd foonathan_memory_vendor
$ mkdir build && cd build
$ cmake ..
$ cmake --build . --target install

make 過程中還會從 github 下載代碼,如有必要,用 sed 命令把 CMake 生成的臨時文件 build/foo_mem-ext-prefix/tmp/foo_mem-ext-gitclone.cmake 中 github.com 替換成 hub.fastgit.org

安裝 FastDDS

$ git clone https://github.com/eProsima/Fast-DDS.git
$ mkdir Fast-DDS/build && cd Fast-DDS/build
$ cmake ..
$ cmake --build . --target install

安裝 Fast DDS Gen(IDL 生成 C++ 代碼)

git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git
cd Fast-DDS-Gen
gradle assemble

上述步驟中存在諸多 gradle 的坑:

🕳 5:系統 gradle 版本和 FastDDS 的不匹配

使用文件夾下 ./gradlew assemble,自動下載和當前 FastDDS 匹配的 gradle 版本

🕳 6:gradlew 可能因代理問題無法下載 gradle 包

  1. 手動下載 gradle 包,放到 ~/Fast-DDS/src/fastddsgen/thirdparty/idl-parser/gradle/wrapper
  2. 編輯 fastddsgen/thirdparty/idl-parser/gradle/wrapper/gradle-wrapper.properties,刪除 distributionUrl 字段的 https://services.gradle.org/distributions/
    distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
    
  3. 運行 ./gradlew assemble,編譯之后的程序在 ~/Fast-DDS-Gen/scripts/fastddsgen 目錄
  4. 將該目錄添加到 PATH 路徑
    PATH=$PATH:~/Fast-DDS-Gen/scripts
    

編譯示例代碼

🕳 7:undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'

~/Fast-DDS/examples/build$ make
[  3%] Built target DeadlineQoSExample
[  5%] Built target DisablePositiveACKs
[  7%] Built target OwnershipStrengthQoSExample
[  7%] Linking CXX executable DynamicHelloWorldExample
/usr/bin/ld: CMakeFiles/DynamicHelloWorldExample.dir/HelloWorldPublisher.cpp.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [C++/DynamicHelloWorldExample/CMakeFiles/DynamicHelloWorldExample.dir/build.make:116: C++/DynamicHelloWorldExample/DynamicHelloWorldExample] Error 1
make[1]: *** [CMakeFiles/Makefile2:1268: C++/DynamicHelloWorldExample/CMakeFiles/DynamicHelloWorldExample.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

在 Fast-DDS/examples/CMakeLists.txt 中添加一行

set(CMAKE_CXX_FLAGS "${CAMKE_CXX_FLAGS} -std=c++11 -pthread")

終於編譯成功!開啟兩個終端,運行下 HelloWorldExample,一個作為 publisher,另一個作為 subscriber。

Fast-DDS/examples/build/C++/HelloWorldExample ./HelloWorldExample publisher
Fast-DDS/examples/build/C++/HelloWorldExample ./HelloWorldExample subscriber

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM