This guide documents the process to build RTAB-Map with LibTorch (C++11 ABI) support and integrate it with ROS 2.
Ensure your workspace is structured as follows for the scripts and commands in this guide to work correctly.
/media/thippe/SDV/Ubuntu/rtab_ws/
├── build/ # Build artifacts
├── install/ # Install artifacts
├── libtorch_cxx11/ # Extracted LibTorch (CXX11 ABI)
│ └── libtorch/
├── src/ # Source code
│ ├── rtabmap/ # Git clone of introlab/rtabmap
│ └── SuperGluePretrainedNetwork/ # Git clone for Python matching
├── env_setup.bash # Environment helper script
├── superpoint_v1.pt # AI Model Weights
├── rtabmap.db # Generated database (after running)
└── trajectory_results.txt # Output poses (after running)
Download and extract LibTorch (CXX11 ABI version) to your workspace.
cd /media/thippe/SDV/Ubuntu/rtab_ws
# Example link (adjust version as needed, must be cxx11 ABI)
wget https://download.pytorch.org/libtorch/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcu121.zip
unzip libtorch-cxx11-abi-shared-with-deps-2.1.0+cu121.zip
mv libtorch libtorch_cxx11We must build the core library manually to ensure it links against LibTorch correctly.
cd /media/thippe/SDV/Ubuntu/rtab_ws/src
git clone https://github.com/introlab/rtabmap.git
cd rtabmap/build
# Configure CMake with AI options
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_TORCH=ON \
-DWITH_PYTHON=ON \
-DTorch_DIR=/media/thippe/SDV/Ubuntu/rtab_ws/libtorch_cxx11/libtorch/share/cmake/Torch \
-DCMAKE_PREFIX_PATH="/media/thippe/SDV/Ubuntu/rtab_ws/libtorch_cxx11/libtorch"
# Compile and Install
make -j$(nproc)
sudo make install
sudo ldconfigGenerate or download superpoint_v1.pt.
# Assuming generated by trace.py or downloaded
cp superpoint_v1.pt /media/thippe/SDV/Ubuntu/rtab_ws/Clone the weights and bridge script.
cd /media/thippe/SDV/Ubuntu/rtab_ws/src
git clone --depth 1 https://github.com/magicleap/SuperGluePretrainedNetwork.git
# IMPORTANT: Copy the bridge script from RTAB-Map to this folder
cp ../src/rtabmap/corelib/src/python/rtabmap_superglue.py SuperGluePretrainedNetwork/We link rtabmap_ros against the system installed library we just built.
cd /media/thippe/SDV/Ubuntu/rtab_ws
# Prevent colcon from rebuilding the library locally
touch src/rtabmap/COLCON_IGNORE
# Clean workspace (optional but recommended)
rm -rf build/ install/
# Export LibTorch path for the linker
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/media/thippe/SDV/Ubuntu/rtab_ws/libtorch_cxx11/libtorch/lib
# Build ROS packages
colcon build --cmake-args -DCMAKE_BUILD_TYPE=ReleaseAfter installation, verifying the setup is critical.
Always source the environment helper first.
cd /media/thippe/SDV/Ubuntu/rtab_ws
source env_setup.bashVerify that RTAB-Map was built with Torch and Python support.
rtabmap --version
# Expected Output:
# With SuperPoint Torch: true
# With Python3: trueEnsure the ROS wrapper is found.
ros2 pkg list | grep rtabmap
# Expected Output:
# rtabmap
# rtabmap_ros
# rtabmap_launch
# ...