1

I need to compile a c++ (98. I cannot migrate yet to 11) code into a mex file.

Unfortunately after upgrading to Xcode 5.1 (which updated also Clang to 3.4 version) I cannot compile the code.

It is the same problem as in here: MEX compile error: unknown type name 'char16_t' Unfortunately the accepted answer is to compile with c++11 support which I cannot do.

Reading in the source code of Clang I found these lines:

// In C11 these are environment macros. In C++11 they are only defined
// as part of <cuchar>. To prevent breakage when mixing C and C++
// code, define these macros unconditionally. We can define them
// unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit
// and 32-bit character literals.
Builder.defineMacro("__STDC_UTF_16__", "1");
Builder.defineMacro("__STDC_UTF_32__", "1"); 

Now.. I wonder why if they define the macro they do not define the type char16_t. And also... I cannot include (file not found) either cuchar (C++11) or uchar.h (C11)

Some idea on how to solve this problem?

EDIT: I'd like to understand if this is a bug of Clang (and I have to signal it) or not. According to C++11 standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2018.html) the marco __STDC_UTF_16__ should be defined in the header file cuchar. But I cannot find that file. So because of that I would expect that the macro is undefined. I think the MEX include file relies on this fact.

Community
  • 1
  • 1
Francesco
  • 1,840
  • 19
  • 24

1 Answers1

2

Just define char16_t (maybe CHAR16_T) as a macro somewhere in your code.

#define char16_t uint16_t

Or, pass -DCHAR16_T=uint16_t flag at compile time.

kyamagu
  • 551
  • 2
  • 5
  • btw: I solved defining at compile time `char16_t` (because matlab looks for that variable) – Francesco Mar 25 '14 at 15:20
  • I don't know if it's a bug, but one thing for sure is that `char16_t` is a C++11 feature and not available in older C++ standard. So I assume the macro just depends on compiler implementation in C++98. – kyamagu Mar 26 '14 at 03:48
  • That is what I thought. So I expect that the macro is not defined in C++98. Unfortunately in the new Clang is not like this. (I had no problem with Clang shipped with Xcode 5.0) – Francesco Mar 26 '14 at 08:06