xcode MEX 编译错误:未知类型名称“char16_t”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22367516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MEX compile error: unknown type name 'char16_t'
提问by p0lAris
I cannot compile any MATLAB MEX code due to the following error:
由于以下错误,我无法编译任何 MATLAB MEX 代码:
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;
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).
据我所知,我的机器上唯一改变的是 Xcode 更新到了 5.1 (5B130a) 版。
Any fix for the time being to compile MEX code in MATLAB?
暂时在 MATLAB 中编译 MEX 代码有什么解决方法吗?
[Running on OS 10.9.2 with Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)]
[在 OS 10.9.2 和 Apple LLVM 版本 5.1 (clang-503.0.38) 上运行(基于 LLVM 3.4svn)]
采纳答案by chappjc
By default, the upgraded Clang doesn't set char16_t
, which is required by MATLAB.
默认情况下,升级后的 Clang 不会设置char16_t
,这是 MATLAB 所要求的。
Quick fix
快速解决
This works for C or C++ code but needs to be done on each mex
command line.
这适用于 C 或 C++ 代码,但需要在每个mex
命令行上完成。
>> mex -Dchar16_t=uint16_t ...
Other solutions below put this definition into the mex configuration or enable C++11.
下面的其他解决方案将此定义放入 mex 配置或启用 C++11。
Permanent solution
永久解决方案
Options:
选项:
- 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 NOTmodifying the MATLAB installation.
- 添加
-std=c++11
到CXXFLAGS
您的 mex 配置文件并编译 .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 安装。
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 并且不能或不想更改为 C++,请按照此其他答案中的解决方案进行操作,或查看下面的替代解决方法。
The other workaround
另一种解决方法
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:
如果由于某种原因您无法启用 C++11 标准,您可以使用预处理器定义char16_t
. 要么放在#define char16_t uint16_t
before#include "mex.h"
,要么用编译器命令行设置它:
-Dchar16_t=uint16_t
Alternatively, use a typedef
, again beforeincluding mex.h:
或者,在包含 mex.h之前typedef
再次使用, :
typedef uint16_t char16_t;
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.
如果这些解决方案不起作用,请尝试更改uint16_t
为UINT16_T
. 此外,其他人报告说,简单地包含 uchar.h 会引入类型,但其他人没有该标题。
回答by Dennis
I experienced the same error, also directly after upgrading to Xcode 5.1.
我也直接在升级到 Xcode 5.1 后遇到了同样的错误。
The relevant lines (818-824) in the file tmwtypes.h, which causes the error, are:
导致错误的文件 tmwtypes.h 中的相关行 (818-824) 是:
#if defined(__STDC_UTF_16__) || (defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT)
typedef char16_t CHAR16_T;
#elif defined(_MSC_VER)
typedef wchar_t CHAR16_T;
#else
typedef UINT16_T CHAR16_T;
#endif
A solution is to simply change the line
一个解决方案是简单地改变行
typedef char16_t CHAR16_T;
into
进入
typedef UINT16_T CHAR16_T;
A must admit that I don't know if this affects any function or behaviour of mex files but at least I'm able to compile my c files again using mex.
必须承认,我不知道这是否会影响 mex 文件的任何功能或行为,但至少我能够使用 mex 再次编译我的 c 文件。
回答by p0lAris
Please see other answers if this method doesn't work.
如果此方法不起作用,请参阅其他答案。
I upgraded my gcc/g++ compilers using homebrew to version 4.8 --> gcc-4.8
and g++-4.8
.
我使用自制软件将我的 gcc/g++ 编译器升级到 4.8 -->gcc-4.8
和g++-4.8
.
After that I changed the following lines in the mexopts.sh file:
之后,我更改了 mexopts.sh 文件中的以下几行:
CXXFLAGS="-fno-common -fexceptions -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -std=c++11"
In my mexopts.sh, this is line 150. I only added the -std=c++11
flag which is what I guess chappjc meant.
在我的 mexopts.sh 中,这是第 150 行。我只添加了-std=c++11
我猜是 chappjc 的意思的标志。
EDIT: This is covered in the update by chappjc!
编辑:chappjc 的更新涵盖了这一点!
回答by Raffi
I just add my own experiment (C++ only). The
我只是添加了我自己的实验(仅限 C++)。这
#define char16_t uint16_t
was causing some problem in the other parts of the mex file. In fact, subsequently to my mex file, char16_t
was properly defined. By tracking the chain of includes, the proper type char16_t
is set in a file named __config
:
在 mex 文件的其他部分引起了一些问题。事实上,随后我的 mex 文件,char16_t
被正确定义。通过跟踪包含链,char16_t
在名为 的文件中设置了正确的类型__config
:
typedef __char16_t char16_t;
which is also the first file included from <algorithm>
. So the hack consists in including algorithm
before mex.h
.
这也是从<algorithm>
. 所以黑客在于包括algorithm
before mex.h
。
#include <algorithm>
#include "mex.h"
and the proper settings are performed, still in a multiplatform manner and without changing anything in the build configuration.
并执行正确的设置,仍然以多平台方式进行,并且不会更改构建配置中的任何内容。
回答by Navid
As part of XCode 5.1.1 char16_t
is defined in __config
, which is called from typeinfo
.
作为 XCode 5.1.1 的一部分,char16_t
在 中定义__config
,从typeinfo
.
You can add
你可以加
#include <typeinfo>
before
前
#include "mex.h"
to have char16_t
defined.
已经char16_t
定义。
回答by Palli Kominak
This post might help: http://www.seaandsailor.com/matlab-xcode6.html
这篇文章可能会有所帮助:http: //www.seaandsailor.com/matlab-xcode6.html
It was easier than I thought. Just replace all 10.x with your OS X version and add -Dchar16_t=UINT16_T
to CLIBS
in mexopts.sh
file.
这比我想象的要容易。只需用OS X的版本替换所有10.x和添加-Dchar16_t=UINT16_T
到CLIBS
在mexopts.sh
文件中。
It worked on OS X 10.9 Mavericks with Xcode 6 installed.
它适用于安装了 Xcode 6 的 OS X 10.9 Mavericks。
回答by tesch1
Include uchar.h before including mex.h...works fine. Also, the answer above (adding -std=c++11) only works for c++, not c.
在包含 mex.h 之前包含 uchar.h ......工作正常。此外,上面的答案(添加 -std=c++11)仅适用于 c++,不适用于 c。
#include <uchar.h>
#include "mex.h"