MEX 编译错误:未知类型名称“char16_t" [英] MEX compile error: unknown type name '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(R2014a 之前的版本)或mex -setup
(R2014a+) 指示的 .xml 文件.这对 OP 有效,但下一个选项也有效.请务必编辑活动/已安装的配置,而不是系统范围的参考.如果您不知道,请尝试下一个解决方案. - 在包含 mex.h 之前,使用
#define
或typedef
创建char16_t
(请参阅下面的其他解决方法"). - 在未来的 MATLAB 版本中,这将得到修复.重新运行
mex -setup
让 MATLAB 为您重新配置它并且它可以工作.从 R2014a 开始,这不起作用. - 作为最后的手段,您可以随时修改 MATLAB 安装,按照 Dennis 的建议修改 MATLAB 的 tmwtypes.h,但我强烈建议不要修改 MATLAB 安装.
- Add
-std=c++11
toCXXFLAGS
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 bymex -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
ortypedef
to createchar16_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
before #include "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
,再次before 包括 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屋!