MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: Compiling MCR C++ dll with VS2010

 Subject: Compiling MCR C++ dll with VS2010 From: Chee Pin Date: 10 May, 2010 17:48:25 Message: 1 of 23 Hi, I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: error C2371: 'char16_t' : redefinition; different basic types May I know if there is a way to avoid this. I am using MCR 7.11 Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Venn Ravichandran Date: 15 Jul, 2010 13:07:05 Message: 2 of 23 Hello, I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types         c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' "Chee Pin " wrote in message ... > Hi, > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > error C2371: 'char16_t' : redefinition; different basic types > > May I know if there is a way to avoid this. I am using MCR 7.11 > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Venn Ravichandran Date: 15 Jul, 2010 13:13:03 Message: 3 of 23 Hello, I figured out how to get rid of the problem by using namespaces. I placed #include inside its own namespace as below: namespace mat { #include } "Venn Ravichandran" wrote in message ... > Hello, > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > "Chee Pin " wrote in message ... > > Hi, > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Chee Pin Date: 20 Jul, 2010 02:17:04 Message: 4 of 23 Are you able to make the code to work? I am running into mxCreateString returning NULL all the time... Chee Pin
 Subject: Compiling MCR C++ dll with VS2010 From: Leo Steenson Date: 27 Jul, 2010 10:33:04 Message: 5 of 23 Hi, Did you add the namespace mat { #include } to the start of both the header file and source file? I am getting the exact same error trying to compile an example for using c++ to work with matlab (opencv example). Could you show me your actual code? I am very new to c++ so any help would be much appreciated. Leo "Venn Ravichandran" wrote in message ... > Hello, > > I figured out how to get rid of the problem by using namespaces. > > I placed #include inside its own namespace as below: > > namespace mat { > #include > } > > > > "Venn Ravichandran" wrote in message ... > > Hello, > > > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > > > > "Chee Pin " wrote in message ... > > > Hi, > > > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Fifo Date: 27 Jul, 2010 13:12:05 Message: 6 of 23 "Venn Ravichandran" wrote in message ... > Hello, > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' Very, Very simple. Go to line 346 of c:\program files\matlab\r2008b\extern\include\matrix.h and change it with what you have in line 576 of c:\program files\microsoft visual studio 10.0\vc\include\yvals.h Than everything will work fine.
 Subject: Compiling MCR C++ dll with VS2010 From: Venn Ravichandran Date: 27 Jul, 2010 17:56:26 Message: 7 of 23 The reason you are getting a conflict is because, as Fifo found out, the matrix.h redefines the function that is in yvals.h. What Fifo suggests is one way to do it. However, I always hesitate to edit the .h files provide by someone else. Simply put, you could end up destroying the interface functionality they are providing you and therefore not a good programming practice. Instead, my encapsulating the matrix.h into its own namespace you avoid conflict: namespace mat { #include } What this means is that you will have to address the variables/functions within matrix.h by adding the "mat::" prefix to them. For instance, instead of being able to call       mxArray x; you will have to use       mat::mxArray x; where "mat" is the namespace within which you included "matrix.h" Cheers, -Venn
 Subject: Compiling MCR C++ dll with VS2010 From: Alex Höck Date: 30 Jul, 2010 09:32:10 Message: 8 of 23 Since I didn't find a usable answer here is my solution which works with the Visual Studio 10 C compiler: #include #if (_MSC_VER >= 1600) #define __STDC_UTF_16__ #endif #include "mex.h" It is necessary to include the yvals.h before mex.h (guess matrix.h is the same, because the redefinition code is in matrix.h).
 Subject: Compiling MCR C++ dll with VS2010 From: Robert Campbell Date: 24 Sep, 2010 17:20:22 Message: 9 of 23 I also have the same problem. I include the mex.h file, which includes the matrix.h file. Otherwise, I might try the namespace approach. Has anyone at Matlab been contacted about this issue?
 Subject: Compiling MCR C++ dll with VS2010 From: Venn Ravichandran Date: 2 Oct, 2010 18:05:07 Message: 10 of 23 The namespace one works for me. Let me know if I can help. -Venn "Alex Höck" wrote in message ... > Since I didn't find a usable answer here is my solution which works with the Visual Studio 10 C compiler: > > #include > #if (_MSC_VER >= 1600) > #define __STDC_UTF_16__ > #endif > #include "mex.h" > > It is necessary to include the yvals.h before mex.h (guess matrix.h is the same, because the redefinition code is in matrix.h).
 Subject: Compiling MCR C++ dll with VS2010 From: José-Luis Guerrero Date: 5 Oct, 2010 12:07:06 Message: 11 of 23 I am trying to do pretty much the same thing. However, i am fairly new to C++ and have never really used namespaces. Where do i have to place: namespace mat{ #include "matrix.h" } At the beginning of the file containing my main{}? In mat.h? (replacing the " #include "matrix.h" "). In both? It does not seem to work when modifying only my main{}. JL "Venn Ravichandran" wrote in message ... > The namespace one works for me. Let me know if I can help. > -Venn > > "Alex Höck" wrote in message ... > > Since I didn't find a usable answer here is my solution which works with the Visual Studio 10 C compiler: > > > > #include > > #if (_MSC_VER >= 1600) > > #define __STDC_UTF_16__ > > #endif > > #include "mex.h" > > > > It is necessary to include the yvals.h before mex.h (guess matrix.h is the same, because the redefinition code is in matrix.h).
 Subject: Compiling MCR C++ dll with VS2010 From: José-Luis Guerrero Date: 5 Oct, 2010 12:33:27 Message: 12 of 23 Answering my own question: The file to modify is mat.h, but you also need to add: using namespace mat; in the same file. Should work smoothly, i.e. assuming you have administrator rights on your machine. I am wondering if this will lead to unwanted behavior further on (i am telling myself that no, but we will see).
 Subject: Compiling MCR C++ dll with VS2010 From: Sander Date: 17 Dec, 2010 13:45:29 Message: 13 of 23 A quick solution is to put the following in your code just before you include the matlab header files: #ifdef _CHAR16T #define CHAR16_T #endif "Venn Ravichandran" wrote in message ... > Hello, > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > "Chee Pin " wrote in message ... > > Hi, > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Zdenek Kalal Date: 19 Dec, 2010 18:40:07 Message: 14 of 23 This fix, #ifdef _CHAR16T #define CHAR16_T #endif worked fine for me, but only if I moved the MEX header (mex.h) at the bottom of all includes in my C file. This didn't work: #ifdef _CHAR16T #define CHAR16_T #endif #include "mex.h" #include "cv.h" but this worked fine: #include "cv.h" #ifdef _CHAR16T #define CHAR16_T #endif #include "mex.h" Zdenek
 Subject: Compiling MCR C++ dll with VS2010 From: Arnold Ju Date: 19 Jan, 2011 18:19:04 Message: 15 of 23 I tried this namespace method, it doesn't work for me so far. My configuration MSVS 2010 Matlab 2009Rb First of all, I'm trying to get the my simple matlab .m file into a .dll file. I finished the wrapper function and in the phase of C++ compiling. However, I couldn't pass the Build so far because of the issue under this thread. I tried the namespace method by replacing the mat.h file #include "matrix.h" with namespace mat { #include } using namespace mat; It didn't work out for me, I still get the same error. I really don't know where to put the namespace for my project. Can I have your email so that I can enclose my snapshots and my code to you. "Leo Steenson" wrote in message ... > Hi, > > Did you add the > > namespace mat { > #include > } > > to the start of both the header file and source file? I am getting the exact same error trying to compile an example for using c++ to work with matlab (opencv example). Could you show me your actual code? I am very new to c++ so any help would be much appreciated. > > Leo > > > > "Venn Ravichandran" wrote in message ... > > Hello, > > > > I figured out how to get rid of the problem by using namespaces. > > > > I placed #include inside its own namespace as below: > > > > namespace mat { > > #include > > } > > > > > > > > "Venn Ravichandran" wrote in message ... > > > Hello, > > > > > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > > > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > > > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > > > > > > > "Chee Pin " wrote in message ... > > > > Hi, > > > > > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Arnold Ju Date: 19 Jan, 2011 21:09:05 Message: 16 of 23 Considering my problem, I'd like to use this namespsace, but I really dont know where to put them. If you take a look at my project, by following your guide, I don't directly include "matrix.h", I think the file "mclmcr.h" include the "matrix.h" I tried to only use this namespace method in matrix.h, but I still got the same problem when I build the whole project. Do you know where to put this namespace in terms of my matrixadd project? "José-Luis Guerrero" wrote in message ... > Answering my own question: > The file to modify is mat.h, but you also need to add: > using namespace mat; > in the same file. Should work smoothly, i.e. assuming you have administrator rights on your machine. > I am wondering if this will lead to unwanted behavior further on (i am telling myself that no, but we will see).
 Subject: Compiling MCR C++ dll with VS2010 From: Arnold Ju Date: 19 Jan, 2011 21:10:05 Message: 17 of 23 Considering my problem, I'd like to use this namespsace, but I really dont know where to put them. If you take a look at my project, by following your guide, I don't directly include "matrix.h", I think the file "mclmcr.h" include the "matrix.h" I tried to only use this namespace method in matrix.h, but I still got the same problem when I build the whole project. Do you know where to put this namespace in terms of my matrixadd project? "José-Luis Guerrero" wrote in message ... > Answering my own question: > The file to modify is mat.h, but you also need to add: > using namespace mat; > in the same file. Should work smoothly, i.e. assuming you have administrator rights on your machine. > I am wondering if this will lead to unwanted behavior further on (i am telling myself that no, but we will see).
 Subject: Compiling MCR C++ dll with VS2010 From: Simon Date: 22 Jun, 2011 01:10:20 Message: 18 of 23 @Venn, I just hit the same problem than while compiling for Matlab. In which file do you make this change? My yvals.h does not have a line cointaining #include Thanks Simon "Venn Ravichandran" wrote in message ... > Hello, > > I figured out how to get rid of the problem by using namespaces. > > I placed #include inside its own namespace as below: > > namespace mat { > #include > } > > > > "Venn Ravichandran" wrote in message ... > > Hello, > > > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > > > > "Chee Pin " wrote in message ... > > > Hi, > > > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Venn Ravichandran Date: 22 Jun, 2011 18:26:05 Message: 19 of 23 @ Simon, Not in yvals.h... it should be in your own source code. Let us say you have two files with the same name. To store them both, you could put them in two separate folders. Later, when you access them, you specify the paths to their specific locations. Similarly, if you are including any of the matlab provided headers in your code, I'd put them in a separate namespace, say conveniently named "mat". This way any of the matlab provided functions don't conflict with those that might already exist (say, via including windows.h). Now, if you want to call the functions inside those matlab headers, you will have to specify the namespace by prefixing the functions with "mat::" to specify their 'path'. Regards, -Venn "Simon " wrote in message ... > @Venn, > I just hit the same problem than while compiling for Matlab. > In which file do you make this change? My yvals.h does not have a line cointaining > #include > Thanks > Simon > > > > "Venn Ravichandran" wrote in message ... > > Hello, > > > > I figured out how to get rid of the problem by using namespaces. > > > > I placed #include inside its own namespace as below: > > > > namespace mat { > > #include > > } > > > > > > > > "Venn Ravichandran" wrote in message ... > > > Hello, > > > > > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > > > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > > > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > > > > > > > "Chee Pin " wrote in message ... > > > > Hi, > > > > > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Simon Date: 22 Jun, 2011 19:52:05 Message: 20 of 23 Venn, What do you mean by my own source code? mex.h? Because when i do the change in mex.h, the error disappear, for an entire set of new errors coming from the files "sourceannotations.h" and "stdio.h". It looks like the problem comes from the prefixing mat::. So have put in front of every function beginning with mx... the prefix mat:: I still end up with this full page of syntax error: c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244) : error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244) : error C2039: 'YesNoMaybe' : is not a member of '`global namespace'' c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244) : error C2146: syntax error : missing ';' before identifier 'SA_YesNoMaybe' c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ... C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(197) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(236) : error C2143: syntax error : missing ';' before '__cdecl' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(236) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Simon "Venn Ravichandran" wrote in message ... > @ Simon, > > Not in yvals.h... it should be in your own source code. > > Let us say you have two files with the same name. To store them both, you could put them in two separate folders. Later, when you access them, you specify the paths to their specific locations. > > Similarly, if you are including any of the matlab provided headers in your code, I'd put them in a separate namespace, say conveniently named "mat". This way any of the matlab provided functions don't conflict with those that might already exist (say, via including windows.h). Now, if you want to call the functions inside those matlab headers, you will have to specify the namespace by prefixing the functions with "mat::" to specify their 'path'. > > Regards, > -Venn >
 Subject: Compiling MCR C++ dll with VS2010 From: Manu Date: 9 Mar, 2012 13:15:12 Message: 21 of 23 Thanks Sander, great solution! -- Manu. "Sander " wrote in message ... > A quick solution is to put the following in your code just before you include the matlab header files: > > #ifdef _CHAR16T > #define CHAR16_T > #endif > > "Venn Ravichandran" wrote in message ... > > Hello, > > > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > > > > "Chee Pin " wrote in message ... > > > Hi, > > > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: David Date: 28 Feb, 2013 20:11:07 Message: 22 of 23 All, I recently ran into this bad problem (that MATLAB and VS2010 definitions clash) in an old project I am resurrecting, and found that MATLAB 2010b libraries / headers have resolved this issue. Thought I should add that to this thread for any future wanderers through this kind of build error. -David "Manu" wrote in message ... > Thanks Sander, great solution! -- Manu. > "Sander " wrote in message ... > > A quick solution is to put the following in your code just before you include the matlab header files: > > > > #ifdef _CHAR16T > > #define CHAR16_T > > #endif > > > > "Venn Ravichandran" wrote in message ... > > > Hello, > > > > > > I have the same problem too. I am using VS2010 with MATLAB 2008b. Here is the exact error message: > > > c:\program files\matlab\r2008b\extern\include\matrix.h(346): error C2371: 'char16_t' : redefinition; different basic types > > > c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(576) : see declaration of 'char16_t' > > > > > > > > > "Chee Pin " wrote in message ... > > > > Hi, > > > > > > > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > > > > > > > error C2371: 'char16_t' : redefinition; different basic types > > > > > > > > May I know if there is a way to avoid this. I am using MCR 7.11 > > > > > > > > Thank you.
 Subject: Compiling MCR C++ dll with VS2010 From: Dongik Date: 18 Mar, 2013 00:57:10 Message: 23 of 23 "Chee Pin" wrote in message ... > Hi, > > I am trying to compile C dll deployment matlab code with vs2010 and i run into the error below: > > error C2371: 'char16_t' : redefinition; different basic types > > May I know if there is a way to avoid this. I am using MCR 7.11 > > Thank you. Project Setting > C/C++ > Language > ... wchart_t --> No (/Zc:wchar_t-)