C2371
Visual C++ Programming Language
Severity: MinorWhat Does This Error Mean?
C2371 means an identifier is declared more than once in the same scope with conflicting types. The message reads: C2371: 'identifier': redefinition; different basic types. This differs from C2086 (same type, just duplicate) — C2371 specifically means the two declarations disagree on the underlying type, which the compiler cannot reconcile. The fix is to remove the duplicate, rename one, or ensure both declarations use exactly the same type.
Affected Models
- Visual Studio 2015–2022
- MSVC v14.x / v17.x
Common Causes
- Two headers that both define the same struct or typedef but with different underlying types
- A typedef and a struct tag using the same name with different representations
- Different headers that define the same name as int in one and unsigned int in another
- A global variable declared extern int in one file and extern long in another
- Conflicting definitions from two third-party libraries that share a name
How to Fix It
-
Locate both declarations. The error message shows the file and line of the second declaration; the first is referenced in the note below the error. Compare the two type signatures.
In Visual Studio, clicking the note under the error in the Output window jumps to the first declaration. This makes it easy to see both declarations side by side.
-
Remove or rename the duplicate. If one declaration comes from a header you control, align its type with the other, or rename the identifier to avoid the conflict.
If both headers come from third-party libraries you cannot modify, use a wrapper or use the types only in separate translation units that do not include both headers.
-
Wrap conflicting headers in namespaces if the conflict is between third-party libraries. This isolates the conflicting names from each other.
Namespace wrapping requires changing all references inside the wrapper. It is a last resort when you cannot modify either header.
Frequently Asked Questions
Why does C2371 appear only in some build configurations?
Preprocessor macros can change a type definition depending on the build target (32-bit vs 64-bit, Debug vs Release, platform defines). A typedef that maps to int in one configuration may map to long in another. The conflict only appears in the configuration where both headers are included and their definitions disagree.