I need to detect the OS name, compiler name, and version of the compiler with C++, as I need to change the setup for each case.
How can I do that?
I recommend define platform in build scripts by providing -D_i386 -DENDIAN=1234 -D_linux. But if you still think another predef project is your friend:
http://sourceforge.net/apps/mediawiki/predef/index.php?title=Main_Page
You won't be able to detect the operating system at compile-time. You will, however, be able to determine the compiler- virtually all compilers define macros indicating their presence, like __GNUC__
or something like that for GCC and MSVC has __MSC_VER__
or something similar. You'll have to check their documentation for the actual macro names, I've forgotten.
Edit: For clarification, you can check what system's headers are included. For example, the Windows headers define a number of macros like WINNT_VER
which give the minimum version of Windows to be targetted. But you can't detect the compiler's executing OS.
For most compilers you can find a list of predefined macros.
Usually you leave that task to the build environment. Either using commands like uname
if you can assume a posixy set up, or by any other mean which is deemed suitable.