I'm kind of really new to this cross platform thing and to say the least I kind of hate dealing with windows but I have to for uni :(
Anyway, I have almost everything I want working on linux and windows but I'm trying to combine them and having one program. I have searched for a bit for this but I can't find a solution. Here is what I have-
#ifdef WIN32
#include <windows.h>
#include <process.h>
#pragma comment(lib, "wsock32.lib")
#else
#include <sys/socket.h>
#include <netdb.h>
void killMe();
#endif
Visual studio tries to 'include' sys/socket and this doesn't exist for windows. I'm hoping there is a simple solution to achieving this.
It works all well if I just comment it out and I know WIN32 is defined as I use a printf() to test it.
The macro is _WIN32
(leading underscore), not WIN32
:
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#pragma comment(lib, "wsock32.lib")
#else
#include <sys/socket.h>
#include <netdb.h>
void killMe();
#endif
See Predefined Macros.
The macro WIN32
is #define
d in the header file WinDef.h
(at line 31). This would explain why WIN32
was available in your .c
source and not in the .h
as the header windows.h
includes WinDef.h
and (presumably) your .c
file includes your header file.