Thread: multiple errors generated by socket headers

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    19

    multiple errors generated by socket headers

    Hi,
    i include in my code some header files from another projects. These is basically networking codel; wrapers around sockets, etc.

    However, i get an output full of errors like this, while compiling:
    Code:
    ....
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(867) : see declaration of 'getservbyname'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock2.h(2196) : error C2375: 'getprotobynumber' : redefinition; different linkage
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(871) : see declaration of 'getprotobynumber'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock2.h(2213) : error C2375: 'getprotobyname' : redefinition; different linkage
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(873) : see declaration of 'getprotobyname'
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(358) : see previous definition of 'IP_ADD_MEMBERSHIP'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WS2tcpip.h(77) : warning C4005: 'IP_DROP_MEMBERSHIP' : macro redefinition
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(359) : see previous definition of 'IP_DROP_MEMBERSHIP'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WS2tcpip.h(78) : warning C4005: 'IP_DONTFRAGMENT' : macro redefinition
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WS2tcpip.h(72) : warning C4005: 'IP_TTL' : macro redefinition
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(360) : see previous definition of 'IP_TTL'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WS2tcpip.h(73) : warning C4005: 'IP_MULTICAST_IF' : macro redefinition
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(355) : see previous definition of 'IP_MULTICAST_IF'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WS2tcpip.h(74) : warning C4005: 'IP_MULTICAST_TTL' : macro redefinition
            c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinSock.h(356) : see previous definition of 'IP_MULTICAST_TTL'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WSPiApi.h(802) : error C3861: 'inet_ntoa': identifier not found, even with argument-dependent lookup
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxsock.h(375) : error C3861: 'WSASetLastError': identifier not found, even with argument-dependent lookup
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxsock.h(396) : error C2440: '=' : cannot convert from 'u_short (__stdcall *)(u_short)' to 'UINT'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxsock.h(396) : error C2440: '=' : cannot convert from 'u_short (__stdcall *)(u_short)' to 'UINT'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxsock.h(396) : fatal error C1003: error count exceeds 100; stopping compilation
    The errors are more or less self-explainable, but behind so many errors there is probably some configuration error... Any help?
    Thanks

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,608
    Check the order of your includes. I had this problem where winsock2.h caused 63 redefinition errors. I just changed the order of the includes and it worked.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    19
    I post my header files, which may help:
    StdAfx.h
    Code:
    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    
    #pragma once
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
    #endif
    
    // Modify the following defines if you have to target a platform prior to the ones specified below.
    // Refer to MSDN for the latest info on corresponding values for different platforms.
    #ifndef WINVER				// Allow use of features specific to Windows 95 and Windows NT 4 or later.
    #define WINVER 0x0400		// Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
    #endif
    
    #ifndef _WIN32_WINNT		// Allow use of features specific to Windows NT 4 or later.
    #define _WIN32_WINNT 0x0400	// Change this to the appropriate value to target Windows 2000 or later.
    #endif						
    
    #ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
    #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
    #endif
    
    #ifndef _WIN32_IE			// Allow use of features specific to IE 4.0 or later.
    #define _WIN32_IE 0x0400	// Change this to the appropriate value to target IE 5.0 or later.
    #endif
    
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS	// some CString constructors will be explicit
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    
    #ifndef _AFX_NO_OLE_SUPPORT
    #include <afxole.h>         // MFC OLE classes
    #include <afxodlgs.h>       // MFC OLE dialog classes
    #include <afxdisp.h>        // MFC Automation classes
    #endif // _AFX_NO_OLE_SUPPORT
    
    #ifndef _AFX_NO_DB_SUPPORT
    #include <afxdb.h>			// MFC ODBC database classes
    #endif // _AFX_NO_DB_SUPPORT
    
    #ifndef _AFX_NO_DAO_SUPPORT
    #include <afxdao.h>			// MFC DAO database classes
    #endif // _AFX_NO_DAO_SUPPORT
    
    #include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>			// MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    common.h
    Code:
    #define MIFARE_KEYLEN 6
    #define MIFARE_KEYNR 0
    #define MIFARE_BLOCKNR 4
    #define MIFARE_BUFLEN 16
    #define FOUT_FILENAME "C:\\id_name_list.dat"
    #define PORT 6000
    #define SERVER_IP "192.168.1.3"
    
    
    #include <winscard.h>
    
    extern "C"{
    #include <ok.h>
    #include <scardcl.h>
    }
    Reader.h
    Code:
    #include "common.h"
    #include "StdAfx.h"
    #include <afxstr.h>
    #include "NDKClient.h"
    
    
    class CReader:public CNDKClient
    {	
    	public:
    		CReader();
    		~CReader();		
    		void start();
    
    	private:
    		SCARD_READERSTATE sReaderState; //structure storing readers and data being monitored
    		SCARDHANDLE hSHandle;
    		SCARDCONTEXT hSContext;
    		void readAndBroadcastID();
    		void UcharToStr(UCHAR *ucDataBuffer, ULONG ulDataBufLen, char *str);
    
    	private:
    		ULONG lastCardState;
    
    };

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    19
    Thanks Bubba!
    I had:
    Code:
    #include "common.h"
    #include "StdAfx.h"
    #include <afxstr.h>
    #include "NDKClient.h"
    and changed to:
    Code:
    #include "NDKClient.h"
    #include "common.h"
    #include "StdAfx.h"
    #include <afxstr.h>
    and it worked!

    Does that mean, that StdAfx includes networking headers?

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    if includes windows headers that makes some defines that confuses winsock2 header
    So when possible - winsock header should go before windows.h header
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,267
    if includes windows headers that makes some defines that confuses winsock2 header
    So when possible - winsock header should go before windows.h header
    winsock2.h already includes windows.h, so the simplest thing to do is just removes your own windows.h includes. Another option is to define _INC_WINDOWS in your project, then it wont matter what order your windows.h and winsock2.h files are included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple declarations of functions errors
    By netwizio in forum C Programming
    Replies: 4
    Last Post: 03-07-2004, 09:02 AM
  2. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  3. Replies: 1
    Last Post: 05-01-2003, 02:52 PM
  4. Socket Project (getting one of multiple clients IP)
    By Cl0wn in forum C Programming
    Replies: 2
    Last Post: 04-05-2003, 12:01 PM
  5. Chat Bot: Multiple headers problem
    By RoD in forum C++ Programming
    Replies: 4
    Last Post: 03-26-2003, 06:07 PM