PR# 19508 C compilation errors due to include in eif_time.h
Problem Report Summary
Submitter: gobobe
Category: EiffelTime
Priority: Medium
Date: 2018/12/07
Class: Bug
Severity: Serious
Number: 19508
Release: 18.11.10.2549
Confidential: No
Status: Analyzed
Responsible:
Environment: win
Synopsis: C compilation errors due to include in eif_time.h
Description
In the file eif_time.h we can read: ~~~~~~~~~~~ #ifdef EIF_WINDOWS /* This will include the definition of struct timeval. The implementation of gettimeofday is in class C_DATE. */ #include <windows.h> #include <winsock2.h> ~~~~~~~~~~~ But this might cause some compilation errors with Windows SDK 10.0.17134 which comes with VisualStudio 2017: ~~~~~~~~~~~ C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared\ws2def.h(235): error C2011: 'sockaddr': 'struct' type redefinition C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock.h(482): note: see declaration of 'sockaddr' C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared\ws2def.h(437): error C2059: syntax error: 'constant' C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared\ws2def.h(633): error C2011: 'sockaddr_in': 'struct' type redefinition C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock.h(309): note: see declaration of 'sockaddr_in' C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock2.h(136):error C2011: 'fd_set': 'struct' type redefinition C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock.h(65): note: see declaration of 'fd_set' C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock2.h(180): error C2011: 'timeval': 'struct' type redefinition C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock.h(108): note: see declaration of 'timeval' C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock2.h(236): error C2011: 'hostent': 'struct' type redefinition C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock.h(164): note: see declaration of 'hostent' C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock2.h(249): error C2011: 'netent': 'struct' type redefinition C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\winsock.h(177): n ote: see declaration of 'netent' .... Many more lines deleted ..... ~~~~~~~~~~~ On the page: https://docs.microsoft.com/en-us/windows/desktop/api/winsock/ns-winsock-timeval I can read: ~~~~~~~~~~ Requirements Minimum supported client Windows 2000 Professional [desktop apps only] Minimum supported server Windows 2000 Server [desktop apps only] Header winsock.h (include Winsock2.h) ~~~~~~~~~~ I tried to replace: #include <winsock2.h> by: #include <winsock.h> in the file eif_time.h, and then the C code compiled with no error anymore. -- Eric Bezault
To Reproduce
Problem Report Interactions
Note that the issue I had was with the EiffelTime, not EiffelStudio. And as a matter of fact I was not using EiffelStudio but another Eiffel compiler to compile this project with EiffelTime. I can confirm that adding the C flag -DWIN32_LEAN_AND_MEAN solves the problem. That being said, it would be nice to explain in the file eif_time.h itself why winsock2.h is used instead of winsock.h as suggested by Microsoft documentation. -- Eric Bezault
We include `winsock2.h` for compatibility with third party C libraries (zeromq and openssl to name a few). It works with all the versions of C compilers we have. Do you have a case where it does not compile? Note that we now compile with the `-DWIN32_LEAN_AND_MEAN` on Windows to avoid further issues.
It's also in file winsock.h for Windows SDK 8.1 and Windows SDK 10.0.10586 (that's all I have installed on my computer). -- Eric Bezault
I confirm that this definition: ~~~~~~~~~~~~~~~~~~~~~ /* * Structure used in select() call, taken from the BSD file sys/time.h. */ struct timeval { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ }; ~~~~~~~~~~~~~~~~~~~~~ is part of winsock.h in my version of Windows SDK. -- Eric Bezault