从MATLAB调用C ++代码? [英] Call C++ code from MATLAB?

查看:113
本文介绍了从MATLAB调用C ++代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,我需要在C ++中编写代码,因为很大程度上依赖于模板。我想从MATLAB调用这个代码:基本上,我需要传递一些参数到C ++代码,并让C ++代码返回一个矩阵到MATLAB。我听说这是可能的东西叫做一个 MEX 文件,我仍在研究。但是我不知道这些MEX文件支持什么。是所有C ++(例如 STL Boost )?它是多么困难?

I have some code which I need to code in C++ due to heavy reliance on templates. I want to call this code from MATLAB: basically, I need to pass some parameters to the C++ code, and have the C++ code return a matrix to MATLAB. I have heard this is possible with something called a MEX file which I am still looking into. However I am not sure what is supported in these MEX files. Is all of C++ (e.g. STL and Boost) supported? How difficult is it?

编辑:我不需要任何共享库,只是头文件的东西,如 shared_ptr

I don't need any shared libraries, just header-only stuff like shared_ptr.

推荐答案

请查看 MEX文件指南,特别是关于C ++的第25-27节​​。
基本的 STL / Boost 数据结构应该可以正常工作,但使用Boost的线程可能会有问题。

cout 将无法按照预期在C ++中工作, mexPrintf 必须使用。

Have a look at the MEX-files Guide, especially Section 25–27 for C++. The basic STL/Boost data structures should work, but threading with Boost could be a problem.
cout will not work as expected in C++, mexPrintf has to be used instead.

这篇关于从MATLAB调用C ++代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆