小编典典

在Windows和Linux上进行C ++编译:ifdef开关

linux

我想在Linux和Windows上运行一些c ++代码。我只想为一个操作系统而不是其他操作系统包括一些代码。有一次可以使用的标准 #ifdef 吗?

就像是:

  #ifdef LINUX_KEY_WORD
    ... // linux code goes here.
  #elif WINDOWS_KEY_WORD
    ... // windows code goes here.
  #else 
  #error "OS not supported!"
  #endif

这个问题确实是重复的,但是这里的答案要好得多,尤其是被接受的答案。


阅读 1022

收藏
2020-06-02

共1个答案

小编典典

采用:

#ifdef __linux__ 
    //linux code goes here
#elif _WIN32
    // windows code goes here
#else

#endif
2020-06-02