Compiling C++11 code as part of a MATLAB mex file

℡╲_俬逩灬. 提交于 2020-01-01 05:15:09

问题


I have a piece of code written in C++11, which I want to compile as part of a MATLAB MEX file for GNU/Linux.

The problem is that MATLAB on Linux supports GCC 4.3 (and earlier) only, and does not support GCC 4.7 which is required to compile my C++11 code.

Is it possible to work-around the problem?

Would it be possible to work-around this by compiling some object files using GCC 4.7 and link them into the MEX file using GCC 4.3?

Thanks in advance!


回答1:


If you can write any code in your 4.3 extension and compile it, then just write code to dlopen a shared object that you wrote and compiled in 4.7. Use the 4.7 .so to do all of your c++11 work, and simply pass your information to it through a C interface. The 4.3 extionsion you write can access all the MATLAB interop stuff.

You could do this a variety of other ways as well, but this is the cleanest. You shouldn't try linking an object file to your 4.3 extension, as you will be accessing two different version of the standard library (quite different), and you can't have multiple defnitions of the same classes with different layouts/methods/etc. You'd be fighting the One Definition Rule (ODR) of c++.



来源:https://stackoverflow.com/questions/9927568/compiling-c11-code-as-part-of-a-matlab-mex-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!