QNX Fast-DDS交叉编译
Clone所需要的仓库
编译fastdds一共需要2个仓库(其实还依赖了Fast-CDR, tinyxml2…等其他仓库,但它们是作为Fast-DDS的submodule,不需要手动clone),下面列出了clone地址(注意是clone地址,不是web地址)
Fast-DDS : https://github.com/eProsima/Fast-DDS.git
foonathan_memory_vendor: https://github.com/eProsima/foonathan_memory_vendor.git
根据需要选择fastdds的版本,这里我们以2.6.0, 编译目标平台是qnx710的fastdds
Clone Fast-DDS
首先clone Fast-DDS,checkout到tag v2.6.0,并且更新所有submodule
git clone https://github.com/eProsima/Fast-DDS.git
cd Fast-DDS
git checkout v2.6.0
git submodule sync --recursive
git submodule update --init --recursive
Clone foonathan_memory_vendor
首先查看Fast-DDS目录内fastrtps.repos文件,查看v2.6.0的Fast-DDS对应foonathan_memory_vendor的版本。可知版本是 v1.2.1(tag)
cat fastrtps.repos
repositories:
foonathan_memory_vendor:
type: git
url: https://github.com/eProsima/foonathan_memory_vendor.git
version: v1.2.1
fastcdr:
type: git
url: https://github.com/eProsima/Fast-CDR.git
version: v1.0.24
fastrtps:
type: git
url: https://github.com/eProsima/Fast-DDS.git
version: v2.6.0
fastddsgen:
type: git
url: https://github.com/eProsima/Fast-DDS-Gen.git
version: v2.1.2
fastddsgen/thirdparty/idl-parser:
type: git
url: https://github.com/eProsima/IDL-Parser.git
version: v1.2.0
clone foonathan_memory_vendor仓库并checkout到v1.2.1
git clone https://github.com/eProsima/foonathan_memory_vendor.git
cd foonathan_memory_vendor
git checkout v1.2.1
QNX cmake编译依赖
根据你qnx编译器安装路径修改QNX_PATH变量,修改后把以下文本保存成qnx710_cross_compile.cmake备用
set(CMAKE_SYSTEM_NAME QNX)
set(QNX_PATH /home/$ENV{USER}/qnx710_safety CACHE STRING "QNX path")
set(CMAKE_FIND_ROOT_PATH ${QNX_PATH}/target/qnx7/aarch64le/usr ${QNX_PATH}/target/qnx7/aarch64le/usr)
set(CMAKE_CXX_COMPILER ${QNX_PATH}/host/linux/x86_64/usr/bin/q++)
set(CMAKE_C_COMPILER ${QNX_PATH}/host/linux/x86_64/usr/bin/qcc)
set(CMAKE_C_FLAGS "-Vgcc_ntoaarch64le")
set(CMAKE_CXX_FLAGS "-Vgcc_ntoaarch64le")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_QNX_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_QNX_SOURCE")
编译顺序
仓库之间是有依赖的,所以要按 foonathan_memory_vendor, Fast-CDR, tinyxml2, Fast-DDS的顺序编译
编译foonathan_memory_vendor
执行以下命令进行编译。注意,所有仓库的安装目录需要一致,这里使用/home/dev/dds_install
cd foonathan_memory_vendor
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/dev/qnx710_cross_compile.cmake -DCMAKE_INSTALL_PREFIX=/home/dev/dds_install #假设qnx cmake文件放在了/home/dev目录,如果不是请自行替换
make
make install
这时候发现编译报错了
make
[ 12%] Performing configure step for 'foo_mem-ext'
container_node_sizes_impl.hpp
CMake Error at src/CMakeLists.txt:99 (message):
Error: Cannot find pre-generated file container_node_sizes_impl.hpp
Please pre-generate the header file container_node_sizes_impl.hpp by
following the steps below:
- Build nodesize_dbg from source:
/home/dev/dds/foonathan_memory_vendor/build/foo_mem-ext-prefix/src/foo_mem-ext/tool/node_size_debugger.cpp
- Transfer nodesize_dbg to QNX target and execute:
nodesize_dbg --code container_node_sizes_impl.hpp
- Transfer generated header file back to your development system
- Set FOONATHAN_MEMORY_CONTAINER_NODE_SIZES_IMPL to the path of the
pre-generated file and pass it to cmake as an argument
-- Configuring incomplete, errors occurred!
提示大概是说,需要用源码/home/dev/dds/foonathan_memory_vendor/build/foo_mem-ext-prefix/src/foo_mem-ext/tool/node_size_debugger.cpp编译成nodesize_dbg,然后上传到目标设备执行命令nodesize_dbg --code container_node_sizes_impl.hpp,把生成的container_node_sizes_impl.hpp头文件回传编译主机,再进行编译
使用以下命令进行nodesize_dbg编译
qcc -Vgcc_ntoaarch64le /home/dev/dds/foonathan_memory_vendor/build/foo_mem-ext-prefix/src/foo_mem-ext/tool/node_size_debugger.cpp -o nodesize_dbg
如果提示error: ‘VERSION’ was not declared in this scope报错,直接修改源码把版本打印这行删掉,不影响。
编译成功后,上传nodesize_dbg到目标机器任意目录,执行以下命令生成container_node_sizes_impl.hpp
nodesize_dbg --code container_node_sizes_impl.hpp
生成container_node_sizes_impl.hpp后,把头文件回传到任意目录,假设是/home/dev/dds/foonathan_memory_vendor/container_node_sizes_impl.hpp
修改foonathan_memory_vendor目录下的CMakeLists.txt文件,在第86行(编译foo_mem-ext的命令)后添加该头文件的路径变量"-DFOONATHAN_MEMORY_CONTAINER_NODE_SIZES_IMPL=/home/dev/dds/foonathan_memory_vendor/container_node_sizes_impl.hpp"
......
externalproject_add(foo_mem-ext
GIT_REPOSITORY git@git.dev.com:mirror/memory.git
GIT_TAG v0.7-1
TIMEOUT 600
# Avoid the update (git pull) and so the recompilation of foonathan_memory library each time.
UPDATE_COMMAND ""
CMAKE_ARGS
-DFOONATHAN_MEMORY_BUILD_EXAMPLES=${BUILD_MEMORY_EXAMPLES}
-DFOONATHAN_MEMORY_BUILD_TESTS=${BUILD_MEMORY_TESTS}
-DFOONATHAN_MEMORY_BUILD_TOOLS=${BUILD_MEMORY_TOOLS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/foo_mem_ext_prj_install
-DFOONATHAN_MEMORY_CONTAINER_NODE_SIZES_IMPL=/home/dev/dds/foonathan_memory_vendor/container_node_sizes_impl.hpp
${extra_cmake_args}
-Wno-dev
${PATCH_COMMAND_STR}
)
......
然后在build目录再次执行make可以编译通过,编译完成后执行make install把库安装到指定目录
编译Fast-CDR
Fast-CDR作为Fast-DDS的submodule在第一步的时候已经同步下来了,如果没有,请回头。
cd Fast-DDS/thirdparty/fastcdr
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/dev/qnx710_cross_compile.cmake -DCMAKE_INSTALL_PREFIX=/home/dev/dds_install
make
make install
编译tinyxml2
tinyxml2作为Fast-DDS的submodule在第一步的时候已经同步下来了,如果没有,请回头。
cd Fast-DDS/thirdparty/tinyxml2
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/dev/qnx710_cross_compile.cmake -DCMAKE_INSTALL_PREFIX=/home/dev/dds_install
make
make install
编译Fast-DDS
cd Fast-DDS
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/dev/qnx710_safety_cross_compile.cmake -DCMAKE_INSTALL_PREFIX=/home/dev/dds_install -DTHIRDPARTY_Asio=ON -DTHIRDPARTY_TinyXML2=ON -DAsio_INCLUDE_DIR=../thirdparty/asio/asio/include/
make
make install
链接时会有报错
[100%] Building CXX object tools/fds/CMakeFiles/fast-discovery-server.dir/server.cpp.o
[100%] Linking CXX executable fast-discovery-server-1.0.0
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `connect'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `freeaddrinfo'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `freeifaddrs'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `getnameinfo'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `getpeername'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `shutdown'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `send'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `getifaddrs'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `getsockopt'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `recv'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `listen'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `sendmsg'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `inet_ntop'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `getsockname'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `if_indextoname'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `gai_strerror'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `sendto'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `bind'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `setsockopt'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `socket'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `inet_pton'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `recvfrom'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `getaddrinfo'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `if_nametoindex'
/home/dev/qnx710_safety/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: ../../src/cpp/libfastrtps.so.2.6.0: undefined reference to `accept'
tools/fds/CMakeFiles/fast-discovery-server.dir/build.make:99: recipe for target 'tools/fds/fast-discovery-server-1.0.0' failed
make[2]: *** [tools/fds/fast-discovery-server-1.0.0] Error 1
CMakeFiles/Makefile2:966: recipe for target 'tools/fds/CMakeFiles/fast-discovery-server.dir/all' failed
make[1]: *** [tools/fds/CMakeFiles/fast-discovery-server.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2
该问题是Linux与qnx的socket链接库不一样导致的
编辑Fast-DDS/tools/fds/CMakeLists.txt,找到第76行target_link_libraries(${PROJECT_NAME} fastrtps fastcdr fastdds::optionparser),把socket链接上
target_link_libraries(${PROJECT_NAME} fastrtps fastcdr fastdds::optionparser socket)
再次make; make install
完成
到安装目录/home/dev/dds_install查看编译好的库
cd /home/dev/dds_install
tree -l -L 2
.
├── bin
│ ├── fastdds
│ ├── fast-discovery-server -> fast-discovery-server-1.0.0
│ ├── fast-discovery-server-1.0.0
│ ├── nodesize_dbg
│ └── ros-discovery
├── include
│ ├── fastcdr
│ ├── fastdds
│ ├── fastrtps
│ ├── foonathan_memory
│ └── tinyxml2.h
├── lib
│ ├── cmake
│ ├── foonathan_memory
│ ├── libfastcdr.so -> libfastcdr.so.1
│ ├── libfastcdr.so.1 -> libfastcdr.so.1.0.24
│ ├── libfastcdr.so.1.0.24
│ ├── libfastrtps.so -> libfastrtps.so.2.6
│ ├── libfastrtps.so.2.6 -> libfastrtps.so.2.6.0
│ ├── libfastrtps.so.2.6.0
│ ├── libfoonathan_memory-0.7.1.a
│ ├── libtinyxml2.so -> libtinyxml2.so.6
│ ├── libtinyxml2.so.6 -> libtinyxml2.so.6.0.0
│ ├── libtinyxml2.so.6.0.0
│ └── pkgconfig
├── share
│ ├── fastcdr
│ ├── fastrtps
│ ├── foonathan_memory
│ └── foonathan_memory_vendor
└── tools
└── fastdds
17 directories, 16 files