Jump to content
  • Advertisement
Sign in to follow this  
chadsxe

Cross - Platform ... How would determine via code what OS you are currently on?

This topic is 4258 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

I am trying to develop an ap for Windows and Linux. I am using VC++ 2005 and the g++ compiler. I want the same source to compile across the two compilers. How can you determine your current platform? For example MyCreateDialogBox(){ if { this is a Windows machine}{ call windows CreatDialog() function; else { this is a Linux machine){ call Linux creat dialong() function; } } The "this is a ..... machine" part is what I am confused about. Sure I can hard code it via global variable and to switch a value based on what OS I am on before I compile, but I was wondering if there is a way for the machine to determine this for me. Maybe I am crazy, but that is why I am hear...hahaha Regards Chad

Share this post


Link to post
Share on other sites
Advertisement
If you're coding for different versions of the same operating system, there's usually an operating system function you can call (E.g. Windows's GetVersionInfo()). If you're coding for different OS's then you'll have to use preprocessor #ifdef blocks, or determine it at compile time, since the executable code just won't run on both OSs with out #ifdefs.

Share this post


Link to post
Share on other sites
I agree with snk_kid. This is exactly what wxWidgets and other toolkits were made for! Not only does wxWidgets work across Windows and Linux (not to mention Mac), but it is also generally easier to use than the various platform libraries.

Share this post


Link to post
Share on other sites
I prefer using QT. (You should open source, or have some money avail to use it)

QT manages pretty much, if not everything, for you.

Sadly I cannot compare to wxWidgets ( I would if I could :o) )

Share this post


Link to post
Share on other sites
Hello,

I hope the fact that I put CreateDialogBox is not swaying you opinions. That was the just the first thing that came to my head. This is my situation...

Using DirectX and VC 2005 in windows
Using SDL and g++ in Linux


Regards

Chad

Share this post


Link to post
Share on other sites
On of the reasons why you couldn't just put code in a normal control structure (no macros) is that the compiler has to account for every function that's used by another function (that it has compiled in the object file[s]). If you're compiling on Windows, and you have a Linux sytem call that's not blocked via macro, then the compiler will search for that function in the linking process, and if it can't find it, it will throw a linker error and abort compilation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!