LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to turn off the "redeclaration" error?

I can't seem to get rid of the redeclaration error. Is there some way I can turn off the compiler from giving me this error?
0 Kudos
Message 1 of 7
(11,809 Views)
The redeclaration errors can be a pain sometimes, but you really shouldn't turn off checking for them, even if you could. They're there to make sure you don't change the declaration of a variable (etc.) in the middle of your program.
You need to find the source of the problem. It can be due to multiple C files using the same header files (depending on how they call each other's functions) or due to the same variables, constants, or functions being declared in multiple .h or .c files.
Do a search across multiple files for whatever is being redeclared.
If the problem is that multiple files are using the same .h file, you can fix that by making all declarations conditional so they get declared only once. Define a constant in your .h file to indicate that it has been read
by the compiler. At the top of the .h file, check if that constant has been defined before declaring anything.
For example:

#ifndef MY_FILE1_DECLARES_READ
#define MY_FILE1_DECLARES_READ
// insert all your declares here
#endif

This way, all your declares will be read only once. Note that the constant (MY_FILE1_DECLARES_READ in this example) needs to have a name unique across all .h files.
Sometimes, the order of the .h files makes a difference, especially if you're using some CVI standard headers and some Windows SDK headers. Some headers test for the existance of constants before declaring their own. Play with the order to see if that helps.
0 Kudos
Message 2 of 7
(11,809 Views)

Hello,

I met the same problem,but it is still not ok when I defined a constant in the .h file like this:

 

 

#ifndef PHTEDTYPEDEFS_H
#define PHTEDTYPEDEFS_H

 

 

#endif

 

the error are below:

 

 API_Ted.c - 2 errors
 "phTedTypeDefs.h"(40,35)   Redeclaration of 'uint32_t'.
 "phTedTypeDefs.h"(58,30)   Redeclaration of 'int32_t'.
DRV_HiT.c - 2 errors
 "phTedTypeDefs.h"(40,35)   Redeclaration of 'uint32_t'.
 "phTedTypeDefs.h"(58,30)   Redeclaration of 'int32_t'.
DRV_HiTa.c - 2 errors
 "phTedTypeDefs.h"(40,35)   Redeclaration of 'uint32_t'.
 "phTedTypeDefs.h"(58,30)   Redeclaration of 'int32_t'.
DRV_Ted.c - 2 errors
 "phTedTypeDefs.h"(40,35)   Redeclaration of 'uint32_t'.
 "phTedTypeDefs.h"(58,30)   Redeclaration of 'int32_t'.
TED_2.c - 2 errors
 "phTedTypeDefs.h"(40,35)   Redeclaration of 'uint32_t'.
 "phTedTypeDefs.h"(58,30)   Redeclaration of 'int32_t'.

0 Kudos
Message 3 of 7
(11,279 Views)

Hello,

 

Anyone can help me? Im a CVI beginner.

 

I inluded a .h file (PHTEDTYPEDEFS.H)

 

 

#ifndef PHTEDTYPEDEFS_H
#define PHTEDTYPEDEFS_H

#ifdef __GNUG__
#include <stdint.h>
#include <cstddef>

#else
  /**
   * \addtogroup GlobalHeaders
   * @{
   */

  /* unsigned types */
  #ifndef __uint8_t_defined
  #define __uint8_t_defined
  

typedef unsigned long   uint32_t;  

  #endif

#endif /* PHTEDTYPEDEFS_H */

 

 

but the stdint.h

define the

 typedef unsigned int        uint32_t;

 

so the error is  "phTedTypeDefs.h"(40,35)   Redeclaration of 'uint32_t'.

 

how s

0 Kudos
Message 4 of 7
(11,241 Views)

See my response to your other post.

 

http://forums.ni.com/t5/LabWindows-CVI/typedef-unsigned-long-long-UINT64/td-p/789580

 

A unsigned long and an unsigned int are the same thing in CVI. You could modify the header for the 3rd party DLL to use unsigned int.

National Instruments
0 Kudos
Message 5 of 7
(11,216 Views)

See my response to your other post.

 

http://forums.ni.com/t5/LabWindows-CVI/typedef-unsigned-long-long-UINT64/td-p/789580

 

A unsigned long and an unsigned int are the same thing in CVI. You could modify the header for the 3rd party DLL to use unsigned int.

National Instruments
0 Kudos
Message 6 of 7
(11,215 Views)

Hi ,

thank you very much,

 

I think i have no other choice but to change the 3rd party header files,yes,it is okay,after i have change the 3rd pary files, there are so many files  which were included in my souce code i have to update,maybe this is not good way .~~

0 Kudos
Message 7 of 7
(11,209 Views)