E1696 cannot open source file "sys/socket.h"

I was working on this project about 6 months ago. It was a windows 10 box and I was using Visual Studio 2017 Community. The project compiled fine. I decided to start working on it again but I have a new computer. Still a windows 10 box and still using VS Community 2017. Except this time when I go to build I'm getting hundreds of errors. This file for example has

E1696 cannot open source file "sys/socket.h"
E1696 cannot open source file "netinet/in.h"
E1696 cannot open source file "unistd.h"
E1696 cannot open source file "netdb.h"
E1696 cannot open source file "arpa/inet.h"

I get 271 errors in all. The path is obviously different on this new box than it was on the old one. Could that be the problem? What am I missing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef SOCKETLIBTYPES_H
#define SOCKETLIBTYPES_H


// ==================================================================================================================
//  Include Files.
// ==================================================================================================================
#ifdef WIN32                // Windows 95 and above
#include "winsock2.h"       // Almost everything is contained in one file.
#include "Ws2tcpip.h"

#ifndef socklen_t
typedef int socklen_t;
#endif

#else                       // UNIX/Linux
#include <sys/types.h>      // Header containing all basic data types and typedefs.
#include <sys/socket.h>     // Header containing socket data types and functions.
#include <netinet/in.h>     // IPv4 and IPv6 stuff.
#include <unistd.h>         // For gethostname()
#include <netdb.h>          // For DNS - gethostbyname()
#include <arpa/inet.h>      // Contains all inet_* functions.
#include <errno.h>          // Contains the error functions.
#include <fcntl.h>          // File control.
#endif

namespace SocketLib
{
	 // =============================================================================================================
	 //  Globals and Typedefs.
	 // =============================================================================================================
#ifdef WIN32  // Windows 95 and above

	 typedef SOCKET sock; // Although sockets are int's on Unix, windows uses it's own typedef of SOCKET to represent 
						  // them. If you look in the Winsock2 source code, you'll see that it is just a typedef for 
						  // int, but there is absolutely no guarantee that it won't change in a later version. 
						  // Therefore, in order to avoid confusion, this library will create it's own basic socket 
						  // descriptor typedef

#else         // UNIX/Linux
	 typedef int sock;    // See the description above.
#endif
	 // =============================================================================================================
	 //  Ports will be in host byte order, but IP addresses in network byte order. It's easier this way; ports are 
	 //  usually accessed as numbers, but IP addresses are better accessed through the string functions.
	 // =============================================================================================================
	 typedef unsigned short int port;        // Define the port type.
	 typedef unsigned long int ipaddress;    // An IP address for IPv4

} // End namespace SocketLib

#endif 
Last edited on
You're trying to include POSIX standard headers which do not exist on Windows, because the system test macro is wrong.

That WIN32 on line 8 should be _WIN32 instead. (Or _MSC_VER, alternatively).
On VS 2017 WIN32 is ok. Might be a 64bit app and then WIN64 is defined
Has so much changed in just 6 months? As I said this worked fine on the same setup not that long ago.

I tried your suggestion. That helped the errors related to that specific error but now I'm getting

C4430 missing type specifier - int assumed. Note: C++ does not support default-int

Every instance of sint64 is an error in the code below. From my research it says that it's always stated as an error but can be turned off with #pragma warning. I'd rather know how to fix it though.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef BASICLIBTIME_H
#define BASICLIBTIME_H

#include "BasicLibTypes.h"
#include <string>

namespace BasicLib
{

	 // ================================================================================================================
	 // These functions get a time value. The Actual meaning of this time is undefined; it is only meant to be relative.
	 // ================================================================================================================
	 sint64 GetTimeMS();
	 sint64 GetTimeS();
	 sint64 GetTimeM();
	 sint64 GetTimeH();


	 // ================================================================================================================
	 // This prints a timestamp in 24 hours hh:mm:ss format.
	 // ================================================================================================================
	 std::string TimeStamp();


	 // ================================================================================================================
	 // This prints a datestamp in YYYY:MM:DD format.
	 // ================================================================================================================
	 std::string DateStamp();


	 // ================================================================================================================
	 //  The Timer Class.
	 // ================================================================================================================
	 class Timer
	 {
	 public:

		  Timer();

		  void Reset(sint64 p_timepassed = 0);

		  sint64 GetMS();
		  sint64 GetS();
		  sint64 GetM();
		  sint64 GetH();
		  sint64 GetD();
		  sint64 GetY();

		  std::string GetString();

	 protected:

		  // This is the system time at which the timer was initialized.
		  sint64 m_inittime;

		  // This is the official "starting time" of the timer.
		  sint64 m_starttime;
	 };

	 inline sint64 seconds(sint64 t) { return t * 1000; }
	 inline sint64 minutes(sint64 t) { return t * 60 * 1000; }
	 inline sint64 hours(sint64 t) { return t * 60 * 60 * 1000; }
	 inline sint64 days(sint64 t) { return t * 24 * 60 * 60 * 1000; }
	 inline sint64 weeks(sint64 t) { return t * 7 * 24 * 60 * 60 * 1000; }
	 inline sint64 years(sint64 t) { return t * 365 * 24 * 60 * 60 * 1000; }

} // End namespace BasicLib

#endif 
MSDN doesn't list WIN32 as a built in macro. (It does list _WIN32):
MSDN wrote:
_WIN32 Defined as 1 when the compilation target is 32-bit ARM, 64-bit ARM, x86, or x64. Otherwise, undefined.

https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017

Maybe WIN32 is defined elsewhere, in which case there's an include-order dependency. Or maybe the docs are wrong. MSDN doesn't have a great track record IMO.

Edit: that's to @Thomas1965: I didn't refresh the page until now - one minute...
Last edited on
closed account (E0p9LyTq)
https://stackoverflow.com/a/662108/9718560

_WIN32 is compiler defined, WIN32 is USER defined.
Well, I can't find anything about sint64 being defined anywhere. I guess it's (supposed to be) defined in BasicLibTypes.h?

In any event, it's almost certainly supposed to be a signed-64 bit int. If it's not there, add it.
Was some project configuration left behind?
Last edited on
closed account (E0p9LyTq)
Well, I can't find anything about sint64 being defined anywhere

I found a couple of references to it being a Mac data type. SInt64.

https://developer.apple.com/documentation/corefoundation/cfnumbertype/kcfnumbersint64type

https://developer.apple.com/documentation/coremedia/kcmmetadatabasedatatype_sint64

@mbozzi BasicLibTypes.h is listed below. Once I changed the WIN32 to _WIN32 as you stated in your first answer (I should've checked all the other files for that same string) that fixed ALL the errors and it compiles fine now.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef BASICLIBTYPES_H
#define BASICLIBTYPES_H
#include <iostream>
#include <fstream>
#include <string>

namespace BasicLib
{

#ifdef WIN32
#if _MSC_VER >= 1300
#define GOODCOMPILER
#else
#define CRAPPYCOMPILER
#endif
#endif

#ifdef __GNUC__
#define GOODCOMPILER
#endif

	 // ================================================================================================================
	 //  This defines the 64 bit datatype.
	 // ================================================================================================================

	 // ================================================================================================================
	 //  LINUX
	 // ================================================================================================================
#ifdef __GNUC__
	 typedef long long int sint64;
	 typedef unsigned long long int uint64;
#endif

	 // ================================================================================================================
	 //  Visual C++
	 // ================================================================================================================
#ifdef WIN32
	 typedef __int64 sint64;
	 typedef unsigned __int64 uint64;
#endif

	 typedef signed long int sint32;
	 typedef unsigned long int uint32;
	 typedef signed short int sint16;
	 typedef unsigned short int uint16;
	 typedef signed char sint8;
	 typedef unsigned char uint8;


	 const double pi = 3.1415926535897932384626433832795;

} // End namespace BasicLib

#endif 
Last edited on
Topic archived. No new replies allowed.