Search code examples
c++cross-platformportabilitymultiplatform

How do i include different headers based on my OS?


I'm writing a portable C++ application. How do I include different headers based on the operating system its running on. Is there a way to do this in C++ or do i have to use the build system?


Solution

  • with preprocessor:

    #ifdef _SUNOS
    //code
    #elseif _LINUX
    //code
    #elseif _HPUX
    //code
    #elseif _WIN32
    //code
    #else
    #error OS not supported
    #endif