c++ type redefinitions

Posted on 2011-05-06
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
    LVL 39

    Expert Comment

    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 39

    Accepted Solution


    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:
    LVL 1

    Author Comment

    ok, thanks :)

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now