Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is WIN32 defined, and how can I include this definition in my project?

I am including a third party header and source file into my project.

At the top of the header there is this:

#if defined(WIN32) || defined(WIN16)
#ifndef MSDOS
#define MSDOS
#endif
#endif

#include <stdio.h>
#include <stdlib.h>
#ifndef MSDOS
#include <unistd.h>
#endif
#include "des.h"

The problem is that #if defined(WIN32) fails and the compilation fails when trying to #include unistd.h which I don't want to do.

I have third party project that works with this header file i.e. WIN32 is defined and it doesn't try to include In Visual Studio I did "Go To Definition" on "WIN32" and was taken to the following definition in WinDefs.h.

#define WIN32

I'm not sure this is where its getting WIN32 definition from, as the third party project does not appear to include "WinDefs.h".

So my problem is, how can I get WIN32 to be defined in my current new project?

like image 280
BeeBand Avatar asked Feb 22 '11 15:02

BeeBand


2 Answers

Depends on your project setup. WIN32 is defined inside the windows header files, but you can pass it to the compiler as well ("-DWIN32" for gcc for example). Try it and see whether it compiles.

like image 153
Axel Avatar answered Nov 02 '22 18:11

Axel


Visual Studio has the built-in define _WIN32. mingw-gcc has WIN32 and _WIN32 built-in so the project was likely tested using gcc. You might add


#if defined(_WIN32) && !defined(WIN32)
#define WIN32
#endif

or just add a -DWIN32 to the CFLAGS.

like image 36
patthoyts Avatar answered Nov 02 '22 18:11

patthoyts