Build
发布时间:2026-08-20 | 浏览:11
To build GTSAM from source, clone or download the latest release from the GTSAM GitHub repository . The current stable release is 4.2, while the main development line is in pre-4.3 mode.
From the repository root, use an out-of-source build:
check is optional, but recommended when you are validating a local build.
Supported Configurations
Required Dependencies
Install these first:
CMake 3.10 or newer
A current C++ toolchain for your platform
Ubuntu package:
Optional Boost Dependency
Boost is now optional. Two CMake flags govern its use:
GTSAM_USE_BOOST_FEATURES
GTSAM_ENABLE_BOOST_SERIALIZATION
If either of those is ON , install Boost 1.70 or newer.
Platform-specific guidance:
macOS: brew install boost
Ubuntu: sudo apt-get install libboost-all-dev
Windows: prefer vcpkg
Optional Dependencies
If TBB is installed and detectable by CMake, GTSAM will use it automatically. Confirm that CMake prints Use Intel TBB : Yes .
Disable it with GTSAM_WITH_TBB=OFF .
On Ubuntu, install it with sudo apt-get install libtbb-dev .
On other platforms, see oneTBB .
GTSAM can be configured to use MKL with GTSAM_WITH_EIGEN_MKL and GTSAM_WITH_EIGEN_MKL_OPENMP , but it does not always improve performance. Benchmark your workload before enabling it.
To use MKL on Linux, Intel provides installation guidance through its package repositories. If you are building the Python wrapper, you may also need:
Ubuntu Packages and PPAs
Ubuntu users can either build from source or use the BorgLab Launchpad archives:
BorgLab Launchpad PPAs
Nightly develop PPA
PPAs are convenient, but they may lag the main repository or carry different package variants depending on the Ubuntu series. For the most current build options, source builds are the safest path.
GTSAM is also available in the AUR .
For Intel-accelerated builds:
check builds and runs all tests. Tests are only built for the check targets so that install does not build them unnecessarily.
Configure first: cmake -S . -B build
Run all tests: cmake --build build --target check
Build timing targets: cmake --build build --target timing
If you are working directly with the generated Makefiles, the classic targets still work:
make check.geometry
make testMatrix.run
On Windows, the preferred modern route is CMake with Ninja from a Developer shell:
Visual Studio builds are also supported, but require a recent Visual Studio installation with C++ tooling and a modern CMake.
Important CMake Options
CMAKE_BUILD_TYPE
Supported values:
Debug : full error checking, no optimization
Release : optimized, no debug symbols
Timing : enables timing statistics
Profiling : intended for profiling runs
RelWithDebInfo : release build with debug symbols
CMAKE_INSTALL_PREFIX
Set the install location:
GTSAM_TOOLBOX_INSTALL_PATH
Set the MATLAB toolbox install path:
GTSAM_BUILD_CONVENIENCE_LIBRARIES
ON (default): faster for developers iterating on tests
OFF : avoids rebuilding the full library twice, better for most users
GTSAM_BUILD_UNSTABLE
ON (default): builds and installs libgtsam_unstable
OFF : excludes unstable code from build and install
Path to the MATLAB mex compiler. If mex is not already in PATH , point it at $MATLABROOT/bin/mex .
GTSAM_BUILD_PYTHON
Enable the Python wrapper with:
If you need a specific interpreter version, add -DGTSAM_PYTHON_VERSION=<version> .
GTSAM_USE_BOOST_FEATURES and GTSAM_ENABLE_BOOST_SERIALIZATION
These flags control the optional Boost dependency. If both are OFF , GTSAM can be built without Boost.
GTSAM makes extensive use of debug assertions, so development work should usually happen in Debug mode. Switch back to Release when benchmarking or running finished code.
Another useful option is _GLIBCXX_DEBUG , which enables additional standard library checks. If you use it to compile GTSAM, anything linking against GTSAM must also use it.
Performance Tips
Use Release mode for production workloads.
Enable TBB on multi-core systems and benchmark with and without it.
Consider -march=native in GTSAM_CMAKE_CXX_FLAGS if portability is not a concern.
Only enable MKL if you have measured a real benefit.
If you use TBB and memory growth is a concern, try -DGTSAM_TBB_BOUNDED_MEMORY_GROWTH=ON .
API Documentation
For API documentation, see:
Python API docs
Wrapper-specific build details are documented in the upstream repository:
Python wrapper README
MATLAB wrapper README