Jump to content
  • Advertisement

Archived

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

toddhd

Need help with Preprocessor directives

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
#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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!