编译C ++ 11代码作为MATLAB mex文件的一部分 [英] Compiling C++11 code as part of a MATLAB mex file

查看:229
本文介绍了编译C ++ 11代码作为MATLAB mex文件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段用C ++ 11编写的代码,我想将其编译为GNU / Linux的MATLAB MEX文件的一部分。

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.

是Linux上的MATLAB仅支持GCC 4.3(和更早版本),并且不支持编译我的C ++ 11代码所需的GCC 4.7。

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.

解决问题?

是否可以通过使用GCC 4.7编译一些目标文件并使用GCC 4.3将它们链接到MEX文件来解决这个问题?

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?

提前感谢!

推荐答案

在你的4.3扩展和编译它,然后只是写代码dlopen一个共享对象,你写和编译在4.7。使用4.7 .so来做你所有的c ++ 11工作,并简单地通过一个C接口传递你的信息给它。你写的4.3扩展可以访问所有的MATLAB互操作的东西。

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.

你可以做各种其他的方式,但这是最干净的。你不应该尝试链接一个目标文件到你的4.3扩展,因为你将访问两个不同版本的标准库(完全不同),你不能有不同的布局/方法/等相同的类的多个定义。你会战胜c ++的单一定义规则(ODR)。

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++.

这篇关于编译C ++ 11代码作为MATLAB mex文件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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