問題描述
由于嚴重依賴模板,我需要用 C++ 編寫一些代碼.我想從 MATLAB 調(diào)用這段代碼:基本上,我需要將一些參數(shù)傳遞給 C++ 代碼,并讓 C++ 代碼向 MATLAB 返回一個矩陣.我聽說這可以通過名為 MEX 的文件實現(xiàn),我仍在研究.但是我不確定這些 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 節(jié).基本的STL/Boost 數(shù)據(jù)結(jié)構(gòu)應(yīng)該可以工作,但使用 Boost 進行線程處理可能會出現(xiàn)問題.cout
在 C++ 中不會按預(yù)期工作,必須使用 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.
這篇關(guān)于從 MATLAB 調(diào)用 C++ 代碼?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!