E2344
C++ Builder Programming Language
Severity: MinorWhat Does This Error Mean?
E2344 means an identifier has been declared more than once in the same scope or translation unit. The message names the duplicate: [BCC64 Error] E2344 Earlier declaration of 'identifier'. A header file that lacks include guards and is included more than once is the most common cause.
Affected Models
- C++ Builder 10.x (Alexandria)
- C++ Builder 11 (Sydney)
- C++ Builder 12 (Athens)
- RAD Studio 11 and 12
Common Causes
- Header file missing #pragma once or #ifndef include guards — included twice in the same translation unit
- The same variable is defined (not just declared) in a header, included from multiple places
- Two headers both declare the same type or function without one being aware of the other
- A local variable with the same name as an outer-scope variable in a nested block
How to Fix It
-
Add #pragma once to the top of every header file you write. This prevents the file from being processed more than once per translation unit.
#pragma once is fully supported by BCC32 and BCC64. Place it as the very first line of the header, before any other content.
-
Move variable definitions out of header files. A header should only declare variables using extern — the definition belongs in exactly one .cpp file.
In the header: extern int MyGlobal; In the .cpp: int MyGlobal = 0; This pattern ensures the variable is defined only once no matter how many .cpp files include the header.
-
If two independent headers both declare the same type, wrap one of them in a conditional: #ifndef MY_TYPE_DEFINED / #define MY_TYPE_DEFINED / ... / #endif.
This is the traditional alternative to #pragma once. It works in all C++ compilers and prevents any block of code from being compiled twice.
Frequently Asked Questions
Is E2344 the same as the MSVC C2086 redefinition error?
Yes — they represent the same underlying problem: an identifier declared or defined more than once. The fix is identical: add include guards and move definitions out of headers.
Can two different #include files both define the same class and cause E2344?
Yes — if two headers each contain a full class definition for the same class name (perhaps different versions of the same library), E2344 fires when both are included. Resolve the conflict by including only one of the headers, or by using namespace qualifiers to distinguish them.