Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: blah_HP on December 01, 2008, 07:02:23 pm

Title: [solved] preprocessor not working (#ifdef WIN32)
Post by: blah_HP on December 01, 2008, 07:02:23 pm
Hello all
Apparently, C:B isnt handling preprocessor directives well (I do understand these should be the compilers fault but oh well, it works on MSVC).

Im using MS VC9 compiler, and the following code fails to compile:

Code
#include "XEngine/GLPrerrequisites.h"

#ifdef WIN32
#include <windows.h>
#else //LINUX
#include <GL/glx.h>
#include <GL/glxext.h>
extern "C" {
extern void (*glXGetProcAddressARB(const GLubyte *procName))( void );
};
#endif

namespace XEngine
{

void* getProcAddress(const char *procname)
{
#ifdef WIN32
  return (void*)wglGetProcAddress((const char*)procname);
#else //LINUX
  return (void*)glXGetProcAddressARB((const GLubyte*)procname);
#endif
}

}

When I try to compile, it complains that the glx.h header cant be found. Well Im using windows, and that header's a linux header, and as you all can see in the code its not supposed to be added! Am I missing something? MSVC compiles this just fine.

Thanks in advance.
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: MortenMacFly on December 02, 2008, 07:09:37 am
Apparently, C:B isnt handling preprocessor directives well
First of all: This is a compiler issue. C::B does not handle any pre-processors at all /except for CC). C::B is just an IDE.
You don't tell what compiler you are using - sol I cannot tell what's exactly the problem is. But here is an advice: If you are using an environment like Cygwin, then WIN32 might indeed NOT be defined as this is a Linux/Unix emulation layer. Everything else would make no sense.

So... start again and tell us something about the environment you are using. At least I can assure you that the "bug" does not reside in C::B but in your project setup / compiler choice. So you are one step further anyways... ;-)
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: Jenna on December 02, 2008, 08:16:46 am
@Martin:
He wrote he use MS VC9

@blah_HP
you should look if you accidently undefine WIN32 at any place, or if you do a 64-bit build, or anything else that makes WIN32 undefined.

I don't use MS compilers, so I can not have a closer look into it.
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: MortenMacFly on December 02, 2008, 10:26:41 am
@Martin:
He wrote he use MS VC9
Yes, but the he wrote:
Am I missing something? MSVC compiles this just fine.
So this made me think he does not use the compiler but another one...?!
I am confused now.
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: blah_HP on December 02, 2008, 05:02:49 pm
OK maybe i wasnt clear enough:

Im using the MSVC9 compiler inside C:B
plus, I can also successfuly build this project inside MSVC9 itself (compiler and IDE)
I know this error is a compiler error, what Im trying to find out is exacly what Moerten mentioned: theres something really weird with my project setup.

Please note that this project builds unmodified inside MSVC9, and thats the catch. Any suggestions?

thanks for the replies so far!
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: rcoll on December 03, 2008, 02:49:18 am
Apparantely the MSVC9 IDE (not the compiler) is defining WIN32, and probably a whole lot more
defines that you don't see.

Go into the compiler setup, and uder "DEFINES" add in WIN32 and see if that helps.

Ringo
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: blah_HP on December 03, 2008, 05:37:42 pm
It worked, thanks Ringo. Problem solved :)
Im amazed at the fact theres not much info regarding this issue around, ive searched everywhere, sounds like im the only one using MS compiler with C:B!
Title: Re: preprocessor not working (#ifdef WIN32)
Post by: MortenMacFly on December 03, 2008, 06:20:51 pm
sounds like im the only one using MS compiler with C:B!
I can assure you: No. ;-)