• ### What is your GameDev Story?

Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Need help with Preprocessor directives

This topic is 5337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

While I''m getting to know C++ rather well in some regards, I''m still a complete idiot other matters, and preprocessor directives is one of those areas that always seems like Greek to me. Here is what I am trying to do, and I''m hoping someone will be kind enough to help me out: I am writing some small OpenGL programs, and since I use both Windows and Linux, its important to me to try and keep the code friendly to both environments. So far, I''ve only coded OpenGL stuff under Windows, using MS VS.NET 2003 C++. Windows has it''s own set of rules for accessing OpenGL libraries. For off, the includes look like this: #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> #include <windows.h> But when you code stuff under linux, it needs them to look like this: #include <GL/gl.h> #include <GL/glu.h> #include <GL/glaux.h> // No windows.h needed here So basically, I need something that looks at the environment (and barring that, perhaps the compiler) and uses the proper set of includes to make things happen. Can anyone assist me in figuring out how to do this, or what resources I might use? Also, if you happen to have any experience in creating open source, cross platform OpenGL stuff and are aware of any "gotchas" I should know ahead of time, it would be much appreciated. Thanks

##### Share on other sites
#ifdef WIN32
Windows Stuff
#else
linux stuff
#endif

Not sure win32 is defined on every compiler under windows... if not, you can pass it as an argument to the compiler.

##### Share on other sites
I think thats supposed to have an underscore before it: _WIN32

##### Share on other sites
You could also simply #include <gl.h> and its ilk (without the prefix directory) and then pass an option to the compiler that tells it to look in the appropriate directory for includes as well as the default directory (for example, Visual Studio has this option under "Additional Include Directories").

This clutters up your source slightly less but requires modifying the makefiles and/or project files -- its kind of a toss up which is "nicer."

##### Share on other sites
Thanks, that was exactly what I was looking for

##### Share on other sites
Can''t you capitalize GL in the windows code, too? Windows is case insensitive so I wouldn''t see how that''s a problem.

##### Share on other sites
quote:
Original post by toddhd
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

Never ever use backslashes. Ever, never. And always use the correct capitalization. Certain crappy operating systems might not care about the case, which is the case with M$-Window$.

In this case, use the latter and ifdef the windows.h part. Or do not include it at all, if I''m not wrong, glaux.h or maybe gl.h include windows.h if needed. That might only be my implementation though and you shouldn''t assume anything about header files (I like that though).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015298
×