www.digitalmars.com         C & C++   DMDScript  

c++.idde - winsock2.h already defined

reply peter.vogel vogel-messtechnik.ch writes:
Hi

I'm trying to build following project with the idde.
#include <windows.h>
#include <winsock2.h>
#include <stdio.h>
//Prototypen
int startWinsock(void);
int main()
{
long rc;
SOCKET s;
SOCKADDR_IN addr;
return 0;
}
int startWinsock(void)
{
WSADATA wsa;
return WSAStartup(MAKEWORD(2,0),&wsa);
}
But I got the following error messages:
sc winsockmin.c -mn -C -WA -S -3 -a8 -c -gf -owinsockmin.obj 
Error: C:\PROGRAMME\DM\BIN\..\include\win32\WINSOCK2.H(85): 'fd_set' is already
defined
Error: C:\PROGRAMME\DM\BIN\..\include\win32\WINSOCK2.H(88): identifier or '(
declarator )' expected
.... etc.
Lines Processed: 124670  Errors: 5  Warnings: 0
Build failed
Where are the double definitions?
If I don't include winsock2.h, WSADATA is not defined!
The program (with some more code) worked fine, when compiled with lcc32.
But I have to use DM, because I have to combine the winsock program with other
code, that uses inline assembler. This didn't compile with lcc32, but with DM.

Best regards, Peter
Oct 03 2003
parent reply Jan Knepper <jan smartsoft.us> writes:
When using winsock2,h you have to:

#define _WINSOCKAPI_            // Prevent winsock.h #include's.

Before you include anything to prevent winsock.h from inclusion as that 
creates conflicts.



peter.vogel vogel-messtechnik.ch wrote:
 Hi
 
 I'm trying to build following project with the idde.
 #include <windows.h>
 #include <winsock2.h>
 #include <stdio.h>
 //Prototypen
 int startWinsock(void);
 int main()
 {
 long rc;
 SOCKET s;
 SOCKADDR_IN addr;
 return 0;
 }
 int startWinsock(void)
 {
 WSADATA wsa;
 return WSAStartup(MAKEWORD(2,0),&wsa);
 }
 But I got the following error messages:
 sc winsockmin.c -mn -C -WA -S -3 -a8 -c -gf -owinsockmin.obj 
 Error: C:\PROGRAMME\DM\BIN\..\include\win32\WINSOCK2.H(85): 'fd_set' is already
 defined
 Error: C:\PROGRAMME\DM\BIN\..\include\win32\WINSOCK2.H(88): identifier or '(
 declarator )' expected
 .... etc.
 Lines Processed: 124670  Errors: 5  Warnings: 0
 Build failed
 Where are the double definitions?
 If I don't include winsock2.h, WSADATA is not defined!
 The program (with some more code) worked fine, when compiled with lcc32.
 But I have to use DM, because I have to combine the winsock program with other
 code, that uses inline assembler. This didn't compile with lcc32, but with DM.
 
 Best regards, Peter
 
 
 
-- ManiaC++ Jan Knepper
Oct 03 2003
parent reply Peter Vogel <Peter_member pathlink.com> writes:
In article <blkg4c$gcp$1 digitaldaemon.com>, Jan Knepper says...
When using winsock2,h you have to:

#define _WINSOCKAPI_            // Prevent winsock.h #include's.

Before you include anything to prevent winsock.h from inclusion as that 
creates conflicts.
Dear Jan Thanks a lot for your help. I don't include windows.h anymore, as it is included with winsock2.h. Now it builds without error. Just for your information: My test program for TCP/IP communication (console) has a size of 96 KB when built with DM and 18 KB with lcc32! It doesn' bother me, as it is only a test program. On my project DLL winsock with a little code only adds 1 KB to 78 KB. Best regards Peter
Oct 04 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Peter Vogel" <Peter_member pathlink.com> wrote in message
news:blmokr$l98$1 digitaldaemon.com...
 In article <blkg4c$gcp$1 digitaldaemon.com>, Jan Knepper says...
When using winsock2,h you have to:

#define _WINSOCKAPI_            // Prevent winsock.h #include's.

Before you include anything to prevent winsock.h from inclusion as that
creates conflicts.
Dear Jan Thanks a lot for your help. I don't include windows.h anymore, as it is included with winsock2.h. Now it builds without error. Just for your information: My test program for TCP/IP communication
(console)
 has a size of 96 KB when built with DM and 18 KB with lcc32!
 It doesn' bother me, as it is only a test program.
 On my project DLL winsock with a little code only adds 1 KB to 78 KB.
DMC code will be a little larger because the runtime library needs to handle exceptions generated by VC++ code, as DMC++ can link to VC++ DLL's and such. But not that much larger, that doesn't explain the size difference. Perhaps you have debug info turned on?
Oct 04 2003
parent reply Peter Vogel <Peter_member pathlink.com> writes:
In article <bln2mr$13i2$1 digitaldaemon.com>, Walter says...
DMC code will be a little larger because the runtime library needs to handle
exceptions generated by VC++ code, as DMC++ can link to VC++ DLL's and such.
But not that much larger, that doesn't explain the size difference. Perhaps
you have debug info turned on?
Indeed, this was the case. I have now 96 K with debug on and 52 K without debug.
Oct 05 2003
parent "Walter" <walter digitalmars.com> writes:
"Peter Vogel" <Peter_member pathlink.com> wrote in message
news:blp44b$ob5$1 digitaldaemon.com...
 In article <bln2mr$13i2$1 digitaldaemon.com>, Walter says...
DMC code will be a little larger because the runtime library needs to
handle
exceptions generated by VC++ code, as DMC++ can link to VC++ DLL's and
such.
But not that much larger, that doesn't explain the size difference.
Perhaps
you have debug info turned on?
Indeed, this was the case. I have now 96 K with debug on and 52 K without debug.
That sounds about right.
Oct 05 2003