CppPilot

MSVC build errors > C2011

C2011: type redefinition

error C2011: 'sockaddr': 'struct' type redefinition

The compiler saw the definition of a class, struct, or enum twice in the same file, usually through headers.

Causes and fixes

  1. A header has no include guard. Add #pragma once at the top of the header, so that including it twice defines its types once.
  2. Two headers define the same type. Keep one definition, in one header, and include it from the other.
  3. windows.h is included before winsock2.h. windows.h includes the old winsock.h, which redefines sockaddr: include winsock2.h first, or define WIN32_LEAN_AND_MEAN before windows.h.

Fix C2011 with CppPilot

CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.

Let the AI fix it in Visual Studio

CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.

Get CppPilot free Get started

Related errors: C4430. See all guides.