This project serves as a lightweight example for demonstrating how to wrap C++ code in MATLAB using GTSAM.
We recommend installing the gtwrap project.
Once the repo is cloned, you can install it via:
mkdir build && cd build
cmake ..
sudo make install
We follow the regular build procedure inside the example_project
directory:
mkdir build && cd build
cmake ..
make -j8
sudo make install
sudo ldconfig # ensures the shared object file generated is correctly loaded
If you have a custom install location, denoted by <install-path>
, you need to update your LD_LIBRARY_PATH
environment variable.
export LD_LIBRARY_PATH=<install-path>/gtsam:$LD_LIBRARY_PATH
Now you can open MATLAB and add the gtsam_toolbox
to the MATLAB path
addpath('/usr/local/gtsam_toolbox')
At this point you are ready to run the example project. Simply run code like regular MATLAB, e.g.
pe = example.PrintExample();
pe.sayHello();
pe.sayGoodbye();
If you see the compiler issue
fatal error: wrap/matlab.h: No such file or directory
1 | #include <wrap/matlab.h>
| ^~~~~~~~~~~~~~~
this means either the gtwrap project is not installed, or you are using the wrapper as provided within GTSAM. In this case, we recommend (re-)installing the gtwrap project as the easiest fix.