03-10-2014 12:48 PM
My project requires both of these files, but when I include them there are "typedef redefinition" build issues. I can reproduce the issue by just creating a minimal project. I can successfully include windows.h or datasize.h but not both. I tried putting windows.h as the very first include file. The path for the windows.h file is c:\program files\national instruments\cvi2013\sdk\include and the path for datasize.h is c:program files\national instruments\cvi2013\include. Any recommendations?
Thanks, Scott
03-11-2014 03:56 PM
Hi Scott,
The error is occurring because of the typedef declaration for "INT32" and "UINT32" occurring in multiple locations. It looks like it is declared in the BaseTsd.h (which is referenced by the datasize.h file) as well as in the datasize.h file. These multiple declarations are allowed as long as the typedefs are the same. However, that is not the case for these two header files. In the header files, we declare:
typedef long INT32; //from database.h
typedef unsigned long UINT32; //from database.h
typedef int INT32; //from BaseTsd.h
typedef unsigned int UINT32; //from BaseTsd.h
As a workaround, save all three header files as a copy to your local machine (datasize.h, BaseTsd.h, and Windows.h). Replace the existing header files with the local copies in your application so that you have editing permissions. Comment out the two repeat typedefs (listed above) from the BaseTsd.h file. See if that allows you to build and run your application.
03-13-2014 10:59 AM
Kelsey,
Thanks. The "local copy" solution is essentially what I ended up doing. I made a local copy of datasize.h and included a modified version of it into my project instead of the official one from NI. The windows.h still has to be included first .
Thanks,
Scott
03-18-2014 09:45 AM
Hi Scott,
When you use the Windows SDK, there is a requirement that you include windows.h before you include any of the CVI headers, so that any such conflicts can be avoided. If you do that, you shouldn't have any conflicts and you shouldn't have to modify any of the include files involved.
You mentioned that you had tried putting windows.h as the very first include and you still saw an error. I couldn't reproduce this. Could you attach a small code snippet that shows this problem?
Luis
03-18-2014 10:09 AM
#include <windows.h>
#include <datasize.h>
#include <cvirte.h>
#include <userint.h>
#include "include.h"
static int panelHandle;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "include.uir", PANEL)) < 0)return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
And here is the compiler error:
Build Status (include.prj - Debug)
include.c - 1 error, 6 warnings
2, 1 In file included from c:\Users\e724950\Documents\Programs\Tools\include prj\include.c:2:
"datasize.h"(104,25) error: typedef redefinition with different types ('char' vs 'signed char')
1, 1 In file included from c:\Users\e724950\Documents\Programs\Tools\include prj\include.c:1:
"Windows.h"(203,1) In file included from c:\program files\national instruments\cvi2013\sdk\include\windows.h:203:
"WinDef.h"(177,1) In file included from c:\program files\national instruments\cvi2013\sdk\include\windef.h:177:
"WinNT.h"(158,1) In file included from c:\program files\national instruments\cvi2013\sdk\include\winnt.h:158:
"BaseTsd.h"(76,29) c:\program files\national instruments\cvi2013\sdk\include\basetsd.h:76:29: note: previous definition is here
Build failed.
The issue seems to be that windows.h (basetsd.h) has already typdef'd some items and that datasize.h is trying to re-typdef them.
If the #if !defined(_BASETSD_H_) on line 106 of datasize.h is moved up to the include INT8 typedef then the compile issue goes away.
Thanks,
Scott
03-21-2014 12:54 PM
Ah, okay. My apologies. I probably only tried to reproduce this with an older version of CVI, without realizing it. This is in fact a bug in CVI (457821). This conflict should be handled in datasize.h, in a similar fashion to how other conflicts are handled in formatio.h and utility.h.
The reason this wasn't a problem before CVI 2013 is because the compiler in the older versions of CVI was not strictly adhering to the C language specification, since the specification requires char, signed char, and unsigned char to all be considered distinct types. This is why, even though CVI 2013 implements char as a signed char, it still complains when it sees the conflicting typedef. In CVI 2012, on the other hand, these two types were not being considered different (since CVI 2012 also implements char as a signed char).
Luis
10-15-2020 08:14 AM
fixed in CVI 2020