User forums > Using Code::Blocks

[solved] preprocessor not working (#ifdef WIN32)

(1/2) > >>

blah_HP:
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
}

}

--- End code ---

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.

MortenMacFly:

--- Quote from: blah_HP on December 01, 2008, 07:02:23 pm ---Apparently, C:B isnt handling preprocessor directives well

--- End quote ---
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... ;-)

Jenna:
@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.

MortenMacFly:

--- Quote from: jens on December 02, 2008, 08:16:46 am ---@Martin:
He wrote he use MS VC9

--- End quote ---
Yes, but the he wrote:

--- Quote from: blah_HP on December 01, 2008, 07:02:23 pm ---Am I missing something? MSVC compiles this just fine.

--- End quote ---
So this made me think he does not use the compiler but another one...?!
I am confused now.

blah_HP:
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!

Navigation

[0] Message Index

[#] Next page

Go to full version