I don't know if this question was answered before, but I couldn't find any relative one.
My question is simple.
Given a simple C program that outputs which operating system we are in, is it possible to detect it on the fly and not recompile it?
We can use macros like _WIN32
, _WIN64
, linux
, etc, but we have to compile the code every time on each system. Can we do it with only one compilation?
Example of a simple program:
#include <stdio.h>
#ifdef _WIN32
#define OS "WINDOWS"
#endif
#ifdef linux
#define OS "LINUX"
#endif
int main(void) {
printf("%s\n", OS);
return 0;
}
For instance we compile the above code with gcc
in linux environment.
Expected outputs will be OS dependent.
Linux : LINUX
Windows : WINDOWS