Matlab使用gtsam_toolbox

  • 看了一圈博客,感觉很多人都不看官方文档的。。。算了,自己写一篇博客吧

  • 首先说一下我自己的平台和版本:

    • MATLAB2017b
    • Ubuntu18.04
    • gtsam-4.0.3

1 编译你的gstam

  • 设定好编译的安装目录,打开matlab工具箱编译功能,配置mex文件目录,正常用cmake-gui就可以直接设定,在这里我简单写一下
cmake -DMEX_COMMAND=/XXX/Matlab/bin/mex \
      -DMATLAB_ROOT=/XXX/Matlab \
      -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON  ..
  • cmake的mkdir build, 设定install dir我默认读这个博客的人都懂的,就不写了

2 编

make -j

3 放到你的安装目录下

  • 系统目录还是自己设定的目录随意啦
make install
  • 这个时候install目录下会有这几个文件,可以看到matlab的toolbox生成成功了
    请添加图片描述

4 配置MATLAB

  • 这个官方文档里写的就很清楚了,翻了几个博客乱七八糟的,后面我贴一下官方怎么说的
  • 首先你要去自己的MATLAB文件夹下删除或者重命名前缀是libstdc++相关的文件,具体目录在
/usr/local/MATLAB/[version]/sys/os/[system]/
/usr/local/MATLAB/[version]/bin/[system]/
  • 由于MATLAB要能找到你编译的libgtsam.so.4文件,如果你gtsam安装在系统目录下,执行sudo ldconfig就可以了
  • 如果你像我一样安装在某个install目录下,在你的shell运行或者在bashrc里添加
export LD_LIBRARY_PATH=/XXX/gtsam-4.0.3/install/lib:$LD_LIBRARY_PATH
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
  • 生效之后重启你的MATLAB
source ~/.bashrc
cd YOURMATLABPATH
./bin/matlab
  • 在matlab添加工具箱,右键文件夹addpath就可以了,不用add sub path
  • 请添加图片描述
  • 最后在MATLAB的控制台里就可以运行示例代码或者测试代码了
>> cd /Users/yourname/toolbox  % Change to wherever you installed the toolbox
>> cd gtsam_examples           % Change to the examples directory
>> gtsamExamples               % Run the GTSAM examples GUI

请添加图片描述

官方文档

Ubuntu
If you have a newer Ubuntu system (later than 10.04), you must make a small modification to your MATLAB installation, due to MATLAB being distributed with an old version of the C++ standard library. Delete or rename all files starting with libstdc++ in your MATLAB installation directory, in paths:

/usr/local/MATLAB/[version]/sys/os/[system]/
/usr/local/MATLAB/[version]/bin/[system]/
Adding the toolbox to your MATLAB path
To get started, first add the toolbox (or gtsam_toolbox) folder to your MATLAB path - in the MATLAB file browser, right-click on the folder and click 'Add to path -> This folder' (do not add the subfolders to your path).

Final setup on Linux
MATLAB needs to know where the GTSAM shared object file (libgtsam.so.4) is so that it can link to it correctly.

System-wide
If you installed GTSAM system-wide (e.g. with sudo make install), then simply run sudo ldconfig.

Custom Install
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
Linker issues
If you compile the MATLAB toolbox and everything compiles smoothly, but when you run any MATLAB script, you get any of the following error messages in MATLAB

Invalid MEX-file '/usr/local/gtsam_toolbox/gtsam_wrapper.mexa64':
Missing symbol 'mexAtExit' required by '/usr/local/gtsam_toolbox/gtsam_wrapper.mexa64'
Missing symbol 'mexCallMATLABWithObject' required by '/usr/local/gtsam_toolbox/gtsam_wrapper.mexa64'
...
run following shell line

export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
before you run MATLAB from the same shell.

This mainly happens if you have GCC >= 5 and newer version MATLAB like R2017a.
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值