This tutorial covers how to build and use C++ libraries - an essential skill for SLAM development where you'll work with Eigen, OpenCV, PCL, g2o, GTSAM, and more.
Dependencies: None (pure C++17)
Local build:
mkdir build
cd build
cmake ..
make -jDocker build:
docker build . -t slam_zero_to_hero:1_10Local:
./build/use_static_lib
./build/use_shared_lib
./build/use_header_onlyDocker:
docker run -it --rm slam_zero_to_hero:1_10| Type | Extension | Linking | Use Case |
|---|---|---|---|
| Static | .a (Linux), .lib (Windows) |
Compile-time | Eigen, small libs |
| Shared | .so (Linux), .dll (Windows) |
Run-time | OpenCV, PCL |
| Header-only | .hpp / .h |
Include only | Eigen, Sophus |
add_library(name STATIC/SHARED sources...)- Create a librarytarget_include_directories()- Specify header locationstarget_link_libraries()- Link libraries togetherfind_package()- Find installed librariesPUBLIC/PRIVATE/INTERFACE- Visibility of dependencies
project/
├── CMakeLists.txt
├── include/
│ └── mylib/
│ └── mylib.hpp # Public headers
├── src/
│ └── mylib.cpp # Implementation
└── examples/
└── main.cpp # Usage example
- Eigen: Header-only library, just include and use
- OpenCV: Shared library, needs
find_package(OpenCV)and linking - g2o/GTSAM: Can be static or shared, need proper CMake setup
- Your own SLAM modules: Often organized as libraries for reusability