How do I check OS with a preprocessor directive?

前端 未结 16 1532
星月不相逢
星月不相逢 2020-11-22 13:53

I need my code to do different things based on the operating system on which it gets compiled. I\'m looking for something like this:

#ifdef OSisWindows
// do         


        
16条回答
  •  执念已碎
    2020-11-22 14:14

    Use #define OSsymbol and #ifdef OSsymbol where OSsymbol is a #define'able symbol identifying your target OS.

    Typically you would include a central header file defining the selected OS symbol and use OS-specific include and library directories to compile and build.

    You did not specify your development environment, but I'm pretty sure your compiler provides global defines for common platforms and OSes.

    See also http://en.wikibooks.org/wiki/C_Programming/Preprocessor

提交回复
热议问题