I just started learning cpp, this is my first post within this site. In case I did anything wrong with this posting, forgive me and instruct, please. If this is posted to the wrong section, please also let me know.
Just a simple example:
On the msdn documentation of the sleep function
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx)
at the requirements, for example there is winbase.h for Win7 and windows.h for 2008R2.
How do you manage, to have only one executable at the end, that can be used with Win7 and 2008R2? As there are stated different include libraries.
If this is a really stupid and easy to answer question I am really sorry.
You have to use #ifdef and depending on the compiler you are using the macros for different operating systems could varry but anyways check out these links
On Windows, all you ever need to include for the usual windows stuff is <windows.h>. That will include winbase.h and so on.
Only if you are using a specific Windows library (such as the networking stuff) that requires extra linking steps do you need to worry about other include files.
An executable produced for Windows 7 should work under Windows 8, unless it makes specific use of features specific to Windows 8.
Thanks Giblit and Duoas for your input.
@Giblit: Do I get you, if I say: You need to compile for different OS prerequisites a program more than one time to an executable? As I already know the #define statements, but as far as I know, these are precompiler statements, these are only executed during the compiling process, not execution of a program. So evaluating the correct librarie during runtime shouldn't be possible, correct?
Is there an other way, to make just ONE .exe work for more than one OS if you use OS specific libraries?
@Duoas: Thanks for your statement, but my example with the sleep was just an simple example of using different libraries on different OS.
To rephrase my example in a more abstract way:
You have OS A where you want to use library a.
You have OS B where you want to use library b.
Is there a way to decide during runtime, not compiling process, which library needs to be used?