Learn how to a build a cloud-first strategyRegister Now


c++ type redefinitions

Posted on 2011-05-06
Medium Priority
Last Modified: 2012-05-11
I'm having a very weird problem with type redefiniton.

I have this DLL which uses the "Winsock2" library.
I have some other DLLs that don't.

But when I link my main DLL to these DLLs (and include the corresponding headers), I'm getting type-redefinition errors.
Each DLL compiles well by itself and they compile well together as long as the DLL that is linked to WinSock is not there...

Each and every header file in the project has a protection:
#ifndef __SomeName__
#define __SomeName__



Open in new window

Why is it happening? :)
Question by:UltraDog
  • 2
LVL 40

Expert Comment

ID: 35708015
This is a known issue.

IIRC you must include winsock2.h before Windows.h or define WIN32_LEAN_AND_MEAN. There is an article on the MSDN I'll try and locate it for you.
LVL 40

Accepted Solution

evilrix earned 1000 total points
ID: 35708067

The Winsock2.h header file internally includes core elements from the Windows.h header file, so there is not usually an #include line for the Windows.h header file in Winsock applications. If an #include line is needed for the Windows.h header file, this should be preceded with the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the Windows.h header defaults to including the Winsock.h header file for Windows Sockets 1.1. The declarations in the Winsock.h header file will conflict with the declarations in the Winsock2.h header file required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header. An example illustrating this is shown below.

Also helpful: http://sourceforge.net/apps/trac/mingw-w64/wiki/winsock2.h%20include%20order

Author Comment

ID: 35708234
ok, thanks :)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question