error C2371: 'char16_t' : redefinition; different basic types

Jun 1, 2011 at 4:59pm
Hi there; I generated a c++ code using matlab. but when i link them i get an error.

this is the error: c:\program files\matlab\r2010a\extern\include\matrix.h(330): error C2371: 'char16_t' : redefinition; different basic types

i am using visual studio 2010 and matlab r2010a.
Jun 1, 2011 at 5:46pm
closed account (zb0S216C)
Can you post the code?

Wazzak
Jun 1, 2011 at 6:09pm
//
// MATLAB Compiler: 4.13 (R2010a)
// Date: Mon May 30 22:22:44 2011
// Arguments: "-B" "macro_default" "-W" "cpplib:libnormal" "-T" "link:lib" "-v"
// "inpaint2" 
//

#ifndef __libnormal_h
#define __libnormal_h 1

#if defined(__cplusplus) && !defined(mclmcrrt_h) && defined(__linux__)
#  pragma implementation "mclmcrrt.h"
#endif
#include "mclmcrrt.h"
#include "mclcppclass.h"
#ifdef __cplusplus
extern "C" {
#endif

#if defined(__SUNPRO_CC)
/* Solaris shared libraries use __global, rather than mapfiles
 * to define the API exported from a shared library. __global is
 * only necessary when building the library -- files including
 * this header file to use the library do not need the __global
 * declaration; hence the EXPORTING_<library> logic.
 */

#ifdef EXPORTING_libnormal
#define PUBLIC_libnormal_C_API __global
#else
#define PUBLIC_libnormal_C_API /* No import statement needed. */
#endif

#define LIB_libnormal_C_API PUBLIC_libnormal_C_API

#elif defined(_HPUX_SOURCE)

#ifdef EXPORTING_libnormal
#define PUBLIC_libnormal_C_API __declspec(dllexport)
#else
#define PUBLIC_libnormal_C_API __declspec(dllimport)
#endif

#define LIB_libnormal_C_API PUBLIC_libnormal_C_API


#else

#define LIB_libnormal_C_API

#endif

/* This symbol is defined in shared libraries. Define it here
 * (to nothing) in case this isn't a shared library. 
 */
#ifndef LIB_libnormal_C_API 
#define LIB_libnormal_C_API /* No special import/export declaration */
#endif

extern LIB_libnormal_C_API 
bool MW_CALL_CONV libnormalInitializeWithHandlers(
       mclOutputHandlerFcn error_handler, 
       mclOutputHandlerFcn print_handler);

extern LIB_libnormal_C_API 
bool MW_CALL_CONV libnormalInitialize(void);

extern LIB_libnormal_C_API 
void MW_CALL_CONV libnormalTerminate(void);



extern LIB_libnormal_C_API 
void MW_CALL_CONV libnormalPrintStackTrace(void);

extern LIB_libnormal_C_API 
bool MW_CALL_CONV mlxInpaint2(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);

extern LIB_libnormal_C_API 
long MW_CALL_CONV libnormalGetMcrID();


#ifdef __cplusplus
}
#endif

#ifdef __cplusplus

/* On Windows, use __declspec to control the exported API */
#if defined(_MSC_VER) || defined(__BORLANDC__)

#ifdef EXPORTING_libnormal
#define PUBLIC_libnormal_CPP_API __declspec(dllexport)
#else
#define PUBLIC_libnormal_CPP_API __declspec(dllimport)
#endif

#define LIB_libnormal_CPP_API PUBLIC_libnormal_CPP_API

#else

#if !defined(LIB_libnormal_CPP_API)
#if defined(LIB_libnormal_C_API)
#define LIB_libnormal_CPP_API LIB_libnormal_C_API
#else
#define LIB_libnormal_CPP_API /* empty! */ 
#endif
#endif

#endif

extern LIB_libnormal_CPP_API void MW_CALL_CONV inpaint2(int nargout, mwArray& inpaintedImg, mwArray& origImg, mwArray& fillImg, mwArray& C, mwArray& D, mwArray& fillMovie, const mwArray& imgFilename, const mwArray& fillFilename, const mwArray& fillColor);

#endif
#endif

this is my generated code. it uses some matlab libraries also
Jun 1, 2011 at 8:31pm
It isn't in what you have posted (at least not that I can see).

Remember that a typedef looks like this: typedef existing_type char16_t; The problem is that you have at least two places in your program giving a typedef for 'char16_t', where the existing type is different.

You'll need to use a search tool (like 'grep') to find all the places in your program sources (yes, all your program sources) where the words "typedef" and "char16_t" appear on the same line. Once you know that, you'll be able to, if no other solution is possible, at least make the underlying types match.

This may be indicative of a bigger problem. If char16_t is defined differently then some parts of your code may be compiled in such a way as to be incompatible.

This may also be just a manifestation of the recommended additions in the C/C++ basic type system and the way that your compiler implements them.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2018.html

Good luck!
Jun 2, 2011 at 10:34am
Looking at VC2010's yvals.h (which defines char16_t) and Matlab's matrix.h here http://www.gridlabd.org/documents/doxygen/1.1/matrix_8h-source.html you shouldn't have a problem. Both check if CHAR16_T is defined before making the typedef. Clearly there's something in your project that's upsetting this.
Topic archived. No new replies allowed.