Please include winsock2 h before windows h

I tried a clone and build of 2.5.5 with the following commands on my Windows 11 m/c setup with Mingw32

mkdir Build
cd Build
cmake -G «MinGW Makefiles» ..
mingw32-make

This is what version of GCC I have installed

$ gcc --version gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.1.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

But mingw32-make step gives compilation errors, this is the last bit :

C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:139:12: warning: inline function 'StringCatNExWorkerA' declared but never defined STRSAFEAPI StringCatNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:138:12: warning: inline function 'StringCatNWorkerW' declared but never defined STRSAFEAPI StringCatNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:137:12: warning: inline function 'StringCatNWorkerA' declared but never defined STRSAFEAPI StringCatNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:136:12: warning: inline function 'StringCatExWorkerW' declared but never defined STRSAFEAPI StringCatExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:135:12: warning: inline function 'StringCatExWorkerA' declared but never defined STRSAFEAPI StringCatExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:134:12: warning: inline function 'StringCatWorkerW' declared but never defined STRSAFEAPI StringCatWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:133:12: warning: inline function 'StringCatWorkerA' declared but never defined STRSAFEAPI StringCatWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:132:12: warning: inline function 'StringCopyNExWorkerW' declared but never defined STRSAFEAPI StringCopyNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:131:12: warning: inline function 'StringCopyNExWorkerA' declared but never defined STRSAFEAPI StringCopyNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:130:12: warning: inline function 'StringCopyNWorkerW' declared but never defined STRSAFEAPI StringCopyNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:129:12: warning: inline function 'StringCopyNWorkerA' declared but never defined STRSAFEAPI StringCopyNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:128:12: warning: inline function 'StringCopyExWorkerW' declared but never defined STRSAFEAPI StringCopyExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:127:12: warning: inline function 'StringCopyExWorkerA' declared but never defined STRSAFEAPI StringCopyExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,unsigned __LONG32 dwFlags); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:126:12: warning: inline function 'StringCopyWorkerW' declared but never defined STRSAFEAPI StringCopyWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc); ^ C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/strsafe.h:125:12: warning: inline function 'StringCopyWorkerA' declared but never defined STRSAFEAPI StringCopyWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc); ^ [ 15%] Building C object CMakeFiles/plctag_dyn.dir/src/platform/windows/platform.c.obj In file included from C:/Users/neil/Documents/NuSoftLtd/Projects/RoutesReports/NR-MPV-SITT-RHTT-Jan2020/MPV-Vehicles/PLC-Dev/Software/Prototype/Sandpit/Build/Mingw32/libplctag/src/platform/windows/platform.h:54:0, from C:\Users\neil\Documents\NuSoftLtd\Projects\RoutesReports\NR-MPV-SITT-RHTT-Jan2020\MPV-Vehicles\PLC-Dev\Software\Prototype\Sandpit\Build\Mingw32\libplctag\src\platform\windows\platform.c:38: C:/Users/neil/.platformio/packages/toolchain-gccmingw32/i686-w64-mingw32/include/Winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp] #warning Please include winsock2.h before windows.h ^ C:\Users\neil\Documents\NuSoftLtd\Projects\RoutesReports\NR-MPV-SITT-RHTT-Jan2020\MPV-Vehicles\PLC-Dev\Software\Prototype\Sandpit\Build\Mingw32\libplctag\src\platform\windows\platform.c:47:21: fatal error: timeapi.h: No such file or directory compilation terminated. CMakeFiles\plctag_dyn.dir\build.make:435: recipe for target 'CMakeFiles/plctag_dyn.dir/src/platform/windows/platform.c.obj' failed mingw32-make[2]: *** [CMakeFiles/plctag_dyn.dir/src/platform/windows/platform.c.obj] Error 1 CMakeFiles\Makefile2:141: recipe for target 'CMakeFiles/plctag_dyn.dir/all' failed mingw32-make[1]: *** [CMakeFiles/plctag_dyn.dir/all] Error 2 makefile:134: recipe for target 'all' failed mingw32-make: *** [all] Error 2

What am I doing wrong ?

Forum

  • Beginners
  • Windows Programming
  • UNIX/Linux Programming
  • General C++ Programming
  • Lounge
  • Jobs
  • Forum
  • Windows Programming
  • [wxWidgets] Please include winsock2.h be

[wxWidgets] Please include winsock2.h before windows.h

My wxWidgets app includes a file transfer using TCP sockets and everything works fine.

But I always get this warning:

#warning Please include winsock2.h before windows.h [-Wcpp]

I know wx has to includes windows.h, so I assume I would just have to move my include before that, but I can’t figure out where?

I’m using mingw-w64 in C::B.

Topic archived. No new replies allowed.

The Problem

This particular issue I run into much more frequently than I would like (full pathnames removed for brevity):

ws2def.h(91): warning C4005: ‘AF_IPX’ : macro redefinition
winsock.h(460) : see previous definition of ‘AF_IPX’
ws2def.h(131): warning C4005: ‘AF_MAX’ : macro redefinition
winsock.h(479) : see previous definition of ‘AF_MAX’
ws2def.h(168): warning C4005: ‘SO_DONTLINGER’ : macro redefinition
winsock.h(402) : see previous definition of ‘SO_DONTLINGER’
ws2def.h(212): error C2011: ‘sockaddr’ : ‘struct’ type redefinition
winsock.h(485) : see declaration of ‘sockaddr’
ws2def.h(390): error C2059: syntax error : ‘constant’
ws2def.h(524): warning C4005: ‘IN_CLASSA’ : macro redefinition
winsock.h(287) : see previous definition of ‘IN_CLASSA’

The Cause

The problem is due to an incompatibility between winsock.h and WinSock2.h. This usually occurs when something has included Windows.h (which includes winsock.h) before WinSock2.h, like this:

#include <Windows.h>
#include <WinSock2.h>

int main( int argc, char* argv[] )
{
  return 0;
}

Of course, finding where this include ordering has occurred is often more complex than this example. Turn on the “Show Includes” compiler option and look in the output window of your build to trace the occurrence to your source files.

The Solution

You basically have three options to fix this:

Option 1: WIN32_LEAN_AND_MEAN

Defining WIN32_LEAN_AND_MEAN will reduce the size of the Windows headers by excluding several APIs, including Windows Sockets.

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <WinSock2.h>

int main( int argc, char* argv[] )
{
  return 0;
}

Option 2: Explicitly include WinSock2.h before Windows.h

By explicitly including WinSock2.h before every place that you Windows.h, you prevent the collision. However, this can be quite cumbersome at times.
UPDATE 2011-11-12:This method can cause issues with struct packing and alignment if WIN32 isn’t defined before including WinSock2.h (see Oren’s comment below). To resolve this issue, either define WIN32 as a preprocessor flag in your project or explicitly define #WIN32 prior to the WinSock2.h include as I’ve done below.

#ifndef WIN32
  #define WIN32
#endif
#include <WinSock2.h>
#include <Windows.h>

int main( int argc, char* argv[] )
{
  return 0;
}

Option 3: Create a WinSock Wrapper Header

This option creates a header file that prevents the collision in the first place and then you include this at (or nearest as possible) to the top of every file that needs WinSock2.h.

The following is based on code from this stackoverflow answer.
#ifndef _WINSOCK_WRAPPER_H_
#define _WINSOCK_WRAPPER_H_

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _WINDOWS_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif

#include <winsock2.h>

#pragma comment(lib, "ws2_32.lib")

#endif
If the #pragma option above is unfamiliar to you, the compiler passes it along to the linker telling it to include the lib rather than having to set it in the project settings. Theres more on #pragma comment options over on MSDN.

open

[Windows MinGW] warning Please include winsock2.h before windows.h

ruby -v:

ruby 3.1.0dev (2021-11-23T07:08:53Z master a88b19d3d0) [x64-mingw32]

[ruby-core:106223]


Description

Compile warning from include/ruby/win32.h? Appears with both MINGW64 & UCRT64 builds.

In file included from D:/ruby-mingw/include/ruby-3.1.0/ruby/win32.h:41,
                 from D:/ruby-mingw/include/ruby-3.1.0/ruby/internal/dosish.h:38,
                 from D:/ruby-mingw/include/ruby-3.1.0/ruby/defines.h:78,
                 from D:/ruby-mingw/include/ruby-3.1.0/ruby/ruby.h:25,
                 from D:/ruby-mingw/include/ruby-3.1.0/ruby.h:38,
                 from ../../../../ext/nokogiri/nokogiri.h:68,
                 from ../../../../ext/nokogiri/gumbo.c:30:
C:/msys64/mingw64/x86_64-w64-mingw32/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp]
   15 | #warning Please include winsock2.h before windows.h
      |  ^~~~~~~

  • History
  • Notes

Sorry. Same warning for all versions back to 2.5.

Also available in: Atom
PDF

Like0

Like0

  • Forum
  • Platform Specific Boards
  • Windows Programming
  • Conflicting winsock.h and winsock2.h

  1. 12-28-2010


    #1


    In the Land of Diddly-Doo


    Conflicting winsock.h and winsock2.h

    Hi, I’ve got this situation here:

    My application uses a static lib that in turn includes winsock2.h. It worked fine until I’ve got some adjustment on the main application to include the windows.h. Now all of these errors came out:

    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(91) : warning C4005: ‘AF_IPX’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(460) : see previous definition of ‘AF_IPX’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(131) : warning C4005: ‘AF_MAX’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(479) : see previous definition of ‘AF_MAX’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(168) : warning C4005: ‘SO_DONTLINGER’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(402) : see previous definition of ‘SO_DONTLINGER’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(212) : error C2011: ‘sockaddr’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(485) : see declaration of ‘sockaddr’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(390) : error C2143: syntax error : missing ‘}’ before ‘constant’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(390) : error C2143: syntax error : missing ‘;’ before ‘constant’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(390) : error C2059: syntax error : ‘constant’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(443) : error C2143: syntax error : missing ‘;’ before ‘}’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(443) : error C4430: missing type specifier — int assumed. Note: C++ does not support default-int
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(443) : error C4430: missing type specifier — int assumed. Note: C++ does not support default-int
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(524) : warning C4005: ‘IN_CLASSA’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(287) : see previous definition of ‘IN_CLASSA’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(530) : warning C4005: ‘IN_CLASSB’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(293) : see previous definition of ‘IN_CLASSB’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(536) : warning C4005: ‘IN_CLASSC’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(299) : see previous definition of ‘IN_CLASSC’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(547) : warning C4005: ‘INADDR_ANY’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(304) : see previous definition of ‘INADDR_ANY’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(549) : warning C4005: ‘INADDR_BROADCAST’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(306) : see previous definition of ‘INADDR_BROADCAST’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\ws2def.h(583) : error C2011: ‘sockaddr_in’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(312) : see declaration of ‘sockaddr_in’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(132) : error C2011: ‘fd_set’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(68) : see declaration of ‘fd_set’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(167) : warning C4005: ‘FD_SET’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(102) : see previous definition of ‘FD_SET’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(176) : error C2011: ‘timeval’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(111) : see declaration of ‘timeval’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(232) : error C2011: ‘hostent’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(167) : see declaration of ‘hostent’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(245) : error C2011: ‘netent’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(180) : see declaration of ‘netent’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(252) : error C2011: ‘servent’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(187) : see declaration of ‘servent’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(264) : error C2011: ‘protoent’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(199) : see declaration of ‘protoent’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(360) : error C2011: ‘WSAData’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(322) : see declaration of ‘WSAData’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(458) : error C2011: ‘sockproto’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(494) : see declaration of ‘sockproto’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(500) : error C2011: ‘linger’ : ‘struct’ type redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(531) : see declaration of ‘linger’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(513) : warning C4005: ‘SOMAXCONN’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(544) : see previous definition of ‘SOMAXCONN’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(542) : warning C4005: ‘FD_READ’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(562) : see previous definition of ‘FD_READ’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(545) : warning C4005: ‘FD_WRITE’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(563) : see previous definition of ‘FD_WRITE’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(548) : warning C4005: ‘FD_OOB’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(564) : see previous definition of ‘FD_OOB’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(551) : warning C4005: ‘FD_ACCEPT’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(565) : see previous definition of ‘FD_ACCEPT’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(554) : warning C4005: ‘FD_CONNECT’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(566) : see previous definition of ‘FD_CONNECT’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(557) : warning C4005: ‘FD_CLOSE’ : macro redefinition
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(567) : see previous definition of ‘FD_CLOSE’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1578) : error C2375: ‘accept’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(742) : see declaration of ‘accept’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1600) : error C2375: ‘bind’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(747) : see declaration of ‘bind’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1619) : error C2375: ‘closesocket’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(752) : see declaration of ‘closesocket’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1638) : error C2375: ‘connect’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(754) : see declaration of ‘connect’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1659) : error C2375: ‘ioctlsocket’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(759) : see declaration of ‘ioctlsocket’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1680) : error C2375: ‘getpeername’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(764) : see declaration of ‘getpeername’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1701) : error C2375: ‘getsockname’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(769) : see declaration of ‘getsockname’
    3>C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock2.h(1724) : error C2375: ‘getsockopt’ : redefinition; different linkage
    3> C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\winsock.h(774) : see declaration of ‘getsockopt’

    Now I’ve searched the web and they said to define WIN_LEAN_AND_MEAN. I’ve tried that and it still didn’t work. I also tried to define WIN_LEAN_AND_MEAN in the static lib, and the library itself can’t be compiled. So, can anyone help me? Thanks in advance.

    Last edited by g4j31a5; 12-28-2010 at 02:19 AM.

    ERROR: Brain not found. Please insert a new brain!

    �Do nothing which is of no use.� — Miyamoto Musashi.


  2. 12-28-2010


    #2


    Banned


    1) winsock2 supercedes winsock.

    2) For reasons that make no sense to me, you have to include winsock2.h before windows.h

    3) You probably need to use include guards in your header files to prevent including the same delarations more than once…

    Code:

    #ifndef HEADER_FILE_NAME
    #define HEADER_FILE_NAME
    
    #include <winsock2.h>
    #include <windows.h>  // yes the order matters
    
    
    // body of declarations
    
    #endif //HEADER_FILE_NAME

    4) The correct define is WIN32_LEAN_AND_MEAN which probably wouldn’t help you in this situation.

    Last edited by CommonTater; 12-28-2010 at 07:13 AM.


  3. 12-28-2010


    #3


    Registered User


    Originally Posted by CommonTater

    2) For reasons that make no sense to me, you have to include winsock2.h before windows.h

    It’s because windows.h unfortunately includes winsock.h.

    The easiest way to get around this problem is to not include windows.h in your code anywhere. winsock2.h will automatically include windows.h for you.

    bit∙hub [bit-huhb] n. A source and destination for information.


  4. 12-28-2010


    #4


    Registered /usr


    I’m at pains to quote Gary Coleman here, seeing as none of his shows were shown in the UK (I did see him in the Simpsons once), but… «What’choo talkin’ ’bout, everybody

    Clearing the FUD here:-

    1. windows.h includes the entire Windows API by default;
    2. defining WIN32_LEAN_AND_MEAN before it prevents all but the core APIs (kernel32, user, gdi, a few others) from being processed;
    3. doing point 2 will allow you to manually include winsock2.h and thus solve your problem.


  5. 12-29-2010


    #5


    In the Land of Diddly-Doo


    First, my bad what I meant was indeed WIN32_LEAN_AND_MEAN. :P

    Second, like SMurf said, if WIN32_LEAN_AND_MEAN, winsock.h won’t be included.

    Thirdly, I’ve solved my problem. ^_^ Actually I’ve got 3 libraries that I am using. Delta 3D, Jetbyte Tools for the Socket Programming, and Logitech SDK for the controller. At first, the Logitech SDK is not being used so it’s fine. But now with the SDK, I have to include windows.h. My fault was I defined WIN32_LEAN_AND_MEAN on both libraries, the Jetbyte Tools and Logitech SDK. But after I analyzed it thoroughly, it was because I’m also including a header from OSG, one of the dependencies of Delta 3D. And in that header there’s no definition of WIN32_LEAN_AND_MEAN at all (and thus the winsock.h was included). So I decided to define it above my main function instead.

    Thanks a lot tho guys. Sorry for the inconvenience.

    ERROR: Brain not found. Please insert a new brain!

    �Do nothing which is of no use.� — Miyamoto Musashi.


  6. 12-29-2010


    #6


    In the Land of Diddly-Doo


    ERROR: Brain not found. Please insert a new brain!

    �Do nothing which is of no use.� — Miyamoto Musashi.


Popular pages

  • Exactly how to get started with C++ (or C) today
  • C Tutorial
  • C++ Tutorial
  • 5 ways you can learn to program faster
  • The 5 Most Common Problems New Programmers Face
  • How to set up a compiler
  • 8 Common programming Mistakes
  • What is C++11?
  • Creating a game, from start to finish

Recent additions

  • How to create a shared library on Linux with GCC — December 30, 2011
  • Enum classes and nullptr in C++11 — November 27, 2011
  • Learn about The Hash Table — November 20, 2011
  • Rvalue References and Move Semantics in C++11 — November 13, 2011
  • C and C++ for Java Programmers — November 5, 2011
  • A Gentle Introduction to C++ IO Streams — October 10, 2011

Similar Threads

  1. Replies: 2

    Last Post: 06-04-2009, 01:57 PM

  2. Replies: 1

    Last Post: 10-08-2008, 05:08 PM

  3. Replies: 5

    Last Post: 12-24-2004, 07:42 PM

  4. Replies: 1

    Last Post: 01-29-2003, 02:42 PM

  5. Replies: 2

    Last Post: 12-27-2002, 07:32 PM

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Allusersprofile desktop windows 10
  • Вирус который не дает переустановить windows 10
  • Canon lbp 3010 driver windows 7 32 bit
  • Как поменять язык системы на windows 10 home single language
  • Что такое центр обновления windows 10