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与苹果LLVM版本5.1 (clang-503.0.38)(基于LLVM 3.4svn)]
7 个解决方案
#1
21
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. - 在您的mex配置文件中添加-std=c++11到CXXFLAGS并编译.cpp文件,而不是.c。mex配置文件是mex。sh (pre-R2014a)或mex -setup (R2014a+)指示的.xml文件。这就是OP的作用,但是下一个选项也可以。一定要编辑活动/安装的配置,而不是系统范围的引用。如果你不知道,可以尝试下一个解决方案。
- Use a
#define
ortypedef
to createchar16_t
before including mex.h (see "other workaround" below). - 使用#define或typedef创建char16_t,包括mex。h(参见下面的“其他工作”)。
- 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. - 在一些未来的MATLAB版本中,这将是固定的。重新运行mex -设置,让MATLAB为您重新配置它,它工作。在R2014a中,这并没有起到什么作用。
- 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.
- 作为最后的手段,您可以随时修改MATLAB的安装,破解MATLAB的tmwtypes。正如Dennis所建议的,但我强烈建议不要修改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放在#include“mex”之前。,或者用编译器命令行设置:
-Dchar16_t=uint16_t
Alternatively, use a typedef
, again before including mex.h:
另外,在使用typedef之前,还需要使用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带来了类型,但是其他的没有那个标题。
#2
8
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中的相关行(818-824)。h,导致错误的是:
#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文件。
#3
2
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
.
我使用homebrew升级了我的gcc/g++编译器,版本为4.8——> gcc-4.8和g++-4.8。
After that I changed the following lines in the mexopts.sh file:
在那之后,我修改了梅克斯的下面几行。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更新的!
#4
2
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被正确定义。通过跟踪包含的链,在一个名为__config的文件中设置了合适的类型char16_t:
typedef __char16_t char16_t;
which is also the first file included from <algorithm>
. So the hack consists in including 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.
正确的设置是在一个多平台的方式下执行的,并且不会改变构建配置中的任何内容。
#5
1
Include uchar.h before including mex.h...works fine. Also, the answer above (adding -std=c++11) only works for c++, not c.
包括uchar。包括前h mex.h……工作很好。同样,上面的答案(添加-std=c++11)只适用于c++,而不是c。
#include <uchar.h>
#include "mex.h"
#6
0
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定义。
#7
0
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.
这比我想象的要容易。只是替换所有10。使用您的OS x版本,并将-Dchar16_t=UINT16_T添加到mexopts中的CLIBS。sh文件。
It worked on OS X 10.9 Mavericks with Xcode 6 installed.
它使用Xcode 6安装了OS X 10.9 Mavericks。
#1
21
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. - 在您的mex配置文件中添加-std=c++11到CXXFLAGS并编译.cpp文件,而不是.c。mex配置文件是mex。sh (pre-R2014a)或mex -setup (R2014a+)指示的.xml文件。这就是OP的作用,但是下一个选项也可以。一定要编辑活动/安装的配置,而不是系统范围的引用。如果你不知道,可以尝试下一个解决方案。
- Use a
#define
ortypedef
to createchar16_t
before including mex.h (see "other workaround" below). - 使用#define或typedef创建char16_t,包括mex。h(参见下面的“其他工作”)。
- 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. - 在一些未来的MATLAB版本中,这将是固定的。重新运行mex -设置,让MATLAB为您重新配置它,它工作。在R2014a中,这并没有起到什么作用。
- 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.
- 作为最后的手段,您可以随时修改MATLAB的安装,破解MATLAB的tmwtypes。正如Dennis所建议的,但我强烈建议不要修改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放在#include“mex”之前。,或者用编译器命令行设置:
-Dchar16_t=uint16_t
Alternatively, use a typedef
, again before including mex.h:
另外,在使用typedef之前,还需要使用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带来了类型,但是其他的没有那个标题。
#2
8
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中的相关行(818-824)。h,导致错误的是:
#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文件。
#3
2
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
.
我使用homebrew升级了我的gcc/g++编译器,版本为4.8——> gcc-4.8和g++-4.8。
After that I changed the following lines in the mexopts.sh file:
在那之后,我修改了梅克斯的下面几行。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更新的!
#4
2
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被正确定义。通过跟踪包含的链,在一个名为__config的文件中设置了合适的类型char16_t:
typedef __char16_t char16_t;
which is also the first file included from <algorithm>
. So the hack consists in including 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.
正确的设置是在一个多平台的方式下执行的,并且不会改变构建配置中的任何内容。
#5
1
Include uchar.h before including mex.h...works fine. Also, the answer above (adding -std=c++11) only works for c++, not c.
包括uchar。包括前h mex.h……工作很好。同样,上面的答案(添加-std=c++11)只适用于c++,而不是c。
#include <uchar.h>
#include "mex.h"
#6
0
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定义。
#7
0
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.
这比我想象的要容易。只是替换所有10。使用您的OS x版本,并将-Dchar16_t=UINT16_T添加到mexopts中的CLIBS。sh文件。
It worked on OS X 10.9 Mavericks with Xcode 6 installed.
它使用Xcode 6安装了OS X 10.9 Mavericks。