Show: Delphi C++
Display Preferences

E2238 Multiple declaration for 'identifier' (C++)

From RAD Studio
Jump to: navigation, search

Go Up to Compiler Errors And Warnings (C++) Index

An identifier was improperly declared more than once.

This error might be caused by conflicting declarations, such as:

  • int a; double a;
  • A function declared in two different ways
  • A label repeated in the same function
  • Some declaration repeated, other than an extern function or a simple variable

Conflicting declarations can also happen by inadvertently including the same header file twice. For example, given:

 struct A { int a; };
 #include "a.h"
 #include "a.h"
 #include "b.h"

myprog.cpp will get two declarations for the struct A. To protect against this, one would write the a.h header file as:

 #ifndef __A_H
 #define __A_H
 struct A { int a; };

This will allow one to safely include a.h several times in the same source code file.

Example Using RTL Headers and OS X Headers

In a multi-device application compiled for the OS X target platform, E2238 can occur because the OS X headers "iodbcunix.h" and "sqltypes.h" declare typedefs for DWORD and ULONG, and the C++Builder sysmac.h, which is included by System.hpp, also provides similar typedefs.

[bccosx Error] iodbcunix.h(128): E2238 Multiple declaration for 'DWORD'
  Full parser context
    Unit1.cpp(10): #include c:\program files (x86)\embarcadero\studio\16.0\include\osx\crtl\iodbcunix.h
[bccosx Error] sysmac.h(1279): E2344 Earlier declaration of 'DWORD'
  Full parser context
    Unit1.cpp(10): #include c:\program files (x86)\embarcadero\studio\16.0\include\osx\crtl\iodbcunix.h

If you must include "iodbcunix.h" and "sqltypes.h" in a translation unit that also uses the System.hpp header, use the following approach:

#include <iodbcunix.h> // Include the OSX headers first
#include <sqltypes.h>  // Include the OSX headers first 
#define _DWORD_DEFINED // Define the _DWORD_DEFINED macro to prevent a new declaration of DWORD
#define _ULONG_DEFINED // Define the _ULONG_DEFINED macro to prevent a new declaration of ULONG
#include <System.hpp>

You can also specify these two macros in the local options of the affected source file:

  1. In the Project Manager, right-click the source file that contains the #include <iodbcunix.h> and #include <sqltypes.h>.
  2. From the context menu, select Edit local options.
  3. On the C++ (Shared Options) page, click the ellipsis [...] in the Conditional Defines field.
  4. On the Conditional Defines dialog box, add the following entries in the entry field:
  5. Click Add.
  6. Click OK.
Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions