MEX编译错误:未知类型名称'char16_t' [英] MEX compile error: unknown type name 'char16_t'

查看:1720
本文介绍了MEX编译错误:未知类型名称'char16_t'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于发生以下错误,我无法编译任何MATLAB MEX代码:

I cannot compile any MATLAB MEX code due to the following error:

In file included from /Applications/MATLAB_R2013a.app/extern/include/mex.h:58:
In file included from /Applications/MATLAB_R2013a.app/extern/include/matrix.h:294:
/Applications/MATLAB_R2013a.app/extern/include/tmwtypes.h:819:9: error: unknown type name 'char16_t'
typedef char16_t CHAR16_T;

在我的机器上改变的唯一的事情就是我记得的是Xcode更新为版本5.1(5B130a)。

The only thing that has changed on my machine as far as I can remember is that Xcode was updated to version 5.1 (5B130a).

暂时在MATLAB中编译MEX代码的任何修复程序?

Any fix for the time being to compile MEX code in MATLAB?

在OS 10.9.2上使用Apple LLVM版本5.1(clang-503.0.38)(基于LLVM 3.4svn)运行]

[Running on OS 10.9.2 with Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)]

推荐答案

默认情况下,升级的Clang不会设置 char16_t ,这是MATLAB需要的。

By default, the upgraded Clang doesn't set char16_t, which is required by MATLAB.

这适用于C或C ++代码,但需要在每个 mex 命令行上完成。

This works for C or C++ code but needs to be done on each mex command line.

>> mex -Dchar16_t=uint16_t ...

以下其他解决方案将此定义放入mex配置或启用C ++ 11。

Other solutions below put this definition into the mex configuration or enable C++11.

选项:


  • 在您的mex配置中添加 -std = c ++ 11 CXXFLAGS 文件并且编译.cpp文件而不是.c。 mex配置文件是mexopts.sh(pre-R2014a)或由 mex -setup (R2014a +)指示的.xml文件。 这对OP有效,但下一个选项也可以。确保编辑活动/安装的配置,而不是系统范围的引用。

  • 使用 #define typedef 在包含mex.h之前创建 char16_t (请参阅下面的其他解决方法)。

  • 在某些未来版本MATLAB,这个会被修复。重新运行 mex -setup 让MATLAB重新配置它,它工作。

  • 作为最后一种手段,你可以随时修改MATLAB的安装,攻破MATLAB的tmwtypes.h,Dennis建议,但我强烈建议 修改MATLAB安装。

  • Add -std=c++11 to CXXFLAGS in your mex configuration file AND compile .cpp files instead of .c. The mex config file is mexopts.sh (pre-R2014a) or the .xml file indicated by mex -setup (R2014a+). This is what worked for OP, but the next option works too. Be sure to edit the active/installed config, not the system-wide reference. Try the next solution if you can't tell.
  • Use a #define or typedef to create char16_t before including mex.h (see "other workaround" below).
  • In some future version of MATLAB, this will have been fixed. Re-run mex -setup to have MATLAB reconfigure it for you and it works. As of R2014a, this doesn't do the trick.
  • As a last resort, you can always modify the MATLAB installation, hacking MATLAB's tmwtypes.h as Dennis suggests, but I strongly suggest NOT modifying the MATLAB installation.

注意:如果你使用C,不能或不想更改为C ++,请按照此其他答案中的解决方案,或查看下面的替代解决方法。

Note: If you are using C and cannot or don't want to change to C++, follow the solution in this other answer, OR see the alternative workaround below.

其他解决方法

如果由于某种原因不能启用C ++ 11标准,可以使用预处理器定义 char16_t 。可以在 之前插入 #define char16_t uint16_t ,或者设置mex.h它与编译器命令行:

If for some reason you are not able to enable the C++11 standard, you can use the preprocessor to define char16_t. Either put #define char16_t uint16_t before #include "mex.h", or set it with the compiler command line:

-Dchar16_t=uint16_t

或者,在之前使用 typedef ,包括mex.h:

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

typedef uint16_t char16_t;

如果这些解决方案不起作用,请尝试更改 uint16_t UINT16_T 。此外,其他人已经报道,只是包括uchar.h带来了类型,但其他人没有那个头。

If these solutions don't work, try changing uint16_t to UINT16_T. Further yet, others have reported that simply including uchar.h brings in the type, but others don't have that header.

这篇关于MEX编译错误:未知类型名称'char16_t'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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