Need help with Preprocessor directives

Started by
5 comments, last by toddhd 19 years, 10 months ago
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
-Todd"Windows dectected that your mouse has moved. Please reboot for the changes to take effect"
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.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
I think thats supposed to have an underscore before it: _WIN32
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."
Thanks, that was exactly what I was looking for
-Todd"Windows dectected that your mouse has moved. Please reboot for the changes to take effect"
Can''t you capitalize GL in the windows code, too? Windows is case insensitive so I wouldn''t see how that''s a problem.
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).

This topic is closed to new replies.

Advertisement