利用X code 5.1下OS X 10.9与MATLAB 2012A MEX文件 [英] Mex files using Xcode 5.1 under OS X 10.9 with MATLAB 2012a

查看:215
本文介绍了利用X code 5.1下OS X 10.9与MATLAB 2012A MEX文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译开发者建立的OpenCV(3.0.0),但是我无法配置我的系统MEX C文件。我试图按照从计算器的建议,目前我可以MEX C ++文件,而不是C的。我所做的就是修改 mexopts.sh ,以便正确 SDKROOT 被使用,也改变了我的部署目标为 10.9

I am trying to compile developer build for OpenCV (3.0.0), however I cannot configure my system to mex C files. I tried to follow suggestions from stackoverflow and currently I can mex c++ files, but not C ones. What I did was edit mexopts.sh so that correct SDKROOT was used, also I changed deployment targets to 10.9.

我mexopts.sh看起来如下:

My mexopts.sh looks as follows:

    #PATCH: MacOSX10.8 // updated manually to 10.9
        CC='llvm-gcc'
        CXX='llvm-g++'
        SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'   

        #SDKROOT='/'
        MACOSX_DEPLOYMENT_TARGET='10.9'
        ARCHS='x86_64'

        # StorageVersion: 1.0
        # CkeyName: GNU C
        # CkeyManufacturer: GNU
        # CkeyLanguage: C
        # CkeyVersion:
        CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
        CFLAGS="$CFLAGS  -fexceptions"
        CLIBS="$MLIBS"
        COPTIMFLAGS='-O2 -DNDEBUG'
        CDEBUGFLAGS='-g'

        CLIBS="$CLIBS -lstdc++"
        # C++keyName: GNU C++
        # C++keyManufacturer: GNU
        # C++keyLanguage: C++
        # C++keyVersion: 

        # OLD
        #CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
        # NEW
        CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -std=c++11"
        CXXLIBS="$MLIBS -lstdc++"
        CXXOPTIMFLAGS='-O2 -DNDEBUG'
        CXXDEBUGFLAGS='-g'

我说只有在 -std = C ++ 11 CXXFLAGS 我是能够编译简单的C ++ code。使用的.cpp 延长保存。这里是code,因为我要编译的文件

Only after I added -std=c++11 to the CXXFLAGS I was able to compile simple C++ code saved using .cpp extension. Here is the code for the file I want to compile

#include <math.h>
#include <matrix.h>
#include <mex.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mexPrintf("Hello World!\n");
}

我将其保存为 test.c以和编译。下面是输出我得到

I save it as test.c and compile. Here is the output i get

mex test.c

2:

在文件从test.c的包括:
在文件从/Applications/MATLAB_R2012a.app/extern/include/matrix.h:295包括:
/Applications/MATLAB_R2012a.app/extern/include/tmwtypes.h:819:9:错误:未知类型
      名称'char16_t
的typedef char16_t CHAR16_T;
        ^
产生1个错误。

In file included from test.c:2: In file included from /Applications/MATLAB_R2012a.app/extern/include/matrix.h:295: /Applications/MATLAB_R2012a.app/extern/include/tmwtypes.h:819:9: error: unknown type name 'char16_t' typedef char16_t CHAR16_T; ^ 1 error generated.

mex: compile of ' "test.c"' failed.

使用MEX错误(行206)
无法成功完成。

Error using mex (line 206) Unable to complete successfully.

在该文件没有 -std = C ++ 11 TEST.CPP 使用了同样的错误>在 CXXFLAGS 。我不是在C / C ++经验,但有一些图书馆或标志我需要添加到解决这一问题?任何建议,链接将是有益的。

The same error was used when the file was saved as test.cpp without -std=c++11 in the CXXFLAGS. I am not experienced in C/C++ but is there some library or flag I need to add to fix the problem? Any suggestions, links would be helpful.

感谢您。

推荐答案

在这不可能通过CXXFLAGS使用C ++ 11 ,无论是由于编译器的限制,或者因为文件必须是C而已,这里不涉及黑客攻击的MATLAB安装(tmwtypes.h)一些可能的解决方法:

When it is not possible to use C++11 via CXXFLAGS, either due to compiler limitation or because the file must be C only, here are some possible workarounds that do not involve hacking the MATLAB installation (tmwtypes.h):

使用了preprocessor定义 char16_t 作为宏 uint16_t (在stdint.h定义) 。无论是使用的#define 的#includemex.h,或者只设置它的命令行( MEX CFLAGS

Use the preprocessor to define char16_t as a macro for uint16_t (defined in stdint.h). Either use a #define before #include "mex.h", or just set it on the command line (mex or CFLAGS):

-Dchar16_t=uint16_t

另外,添加一个的typedef ,又包括前mex.h:

Alternatively, add a typedef, again before including mex.h:

typedef uint16_t char16_t;

要获得 uint16_t ,需要的#include&LT; stdint.h&GT; 。或者尝试 UINT16_T (上限)。

To get uint16_t, you need to #include <stdint.h>. Or try UINT16_T (caps).

最后,如果采用C(编译.c文件), uchar.h 可以定义 char16_t 宏,根据什么修改你的编译器所支持的C标准的:

Last, if using C (compiling .c file), uchar.h may define a char16_t macro, depending on what revision of the the C standard supported by your compiler:

/* In myMexFile.c */
#include <uchar.h>

这篇关于利用X code 5.1下OS X 10.9与MATLAB 2012A MEX文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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