Author Topic: [solved] preprocessor not working (#ifdef WIN32)  (Read 20730 times)

Offline blah_HP

  • Single posting newcomer
  • *
  • Posts: 3
[solved] preprocessor not working (#ifdef WIN32)
« 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.
« Last Edit: December 03, 2008, 05:38:41 pm by blah_HP »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: preprocessor not working (#ifdef WIN32)
« Reply #1 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... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: preprocessor not working (#ifdef WIN32)
« Reply #2 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: preprocessor not working (#ifdef WIN32)
« Reply #3 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline blah_HP

  • Single posting newcomer
  • *
  • Posts: 3
Re: preprocessor not working (#ifdef WIN32)
« Reply #4 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!

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: preprocessor not working (#ifdef WIN32)
« Reply #5 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

Offline blah_HP

  • Single posting newcomer
  • *
  • Posts: 3
Re: preprocessor not working (#ifdef WIN32)
« Reply #6 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!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: preprocessor not working (#ifdef WIN32)
« Reply #7 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. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ