gtsam

install

Ubuntu
sudo add-apt-repository ppa:borglab/gtsam-release-4.0
sudo apt install libgtsam-dev libgtsam-unstable-dev
Windows

gtsam 4.0.1 require Boost components >= v1.43. Refer to boost.

### prepare code
git clone https://github.com/borglab/gtsam.git
cd gtsam
mkdir build
cd build

### cmake configuration
# if use visual studio 2022; if use visual studio 2017, replace with "Visual Studio 16 2019"
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release ..
# 
# if use Ninja
cmake -G "Ninja" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..
# specify install path
cmake -DCMAKE_INSTALL_PREFIX="C:/path/to/install" ..

### build
cmake --build . --config Release

### install
cmake --install . --config Release

Check that GTSAM headers and libraries are available under your install path:

  1. Headers: include/gtsam/
  2. Libs: lib/gtsam.lib, gtsam_unstable.lib (if built)

you can find gtsam-tests.exe, if you add GTSAM_BUILD_TESTS=ON to cmake configuration. and Examples binaries if GTSAM_BUILD_EXAMPLES=ON.

Component Path Description
Static libs build/Release/*.lib Linkable binaries for use in your projects
Headers install/include/gtsam/ For compiling against GTSAM
CMake config files install/lib/cmake/GTSAM/ For find_package(GTSAM)
Executables (optional) build/Release/*.exe Unit tests / examples

use

You can find some examples.

qa

1.遇到错误
Thrown when a linear system is ill-posed. The most common cause for this error is having underconstrained variable.

可能的错误reasons

  • 检查key的格式,递增是否正确
  • 检查noise model是否设置正确
  • pose发生了很大变化,一般是位姿设置正确造成的
2
C:\local\gtsam\include\gtsam\base\Testable.h(122,51): error C2143: syntax error: missing ',' before '<' [D:\calib\build\calib.vcxproj]
  (compiling source file '../src/calib.cpp')
      C:\local\gtsam\include\gtsam\base\Testable.h(122,51):
      the template instantiation context (the oldest one first) is
          C:\local\gtsam\include\gtsam\base\Testable.h(122,10):
          while compiling class template 'gtsam::equals_star'

If this function isn’t used in your code, just comment out the relevent code.

3

Add code below:

#include <boost/bind/bind.hpp>
using namespace boost::placeholders;

// then add gtsam headers
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/nonlinear/Values.h>