本文介绍了在Windows和Linux上的C ++编译:ifdef switch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Linux和Windows上运行一些c ++代码。有一些代码,我想只包括一个操作系统,而不是其他。是否有一次可以使用的标准 #ifdef ?
类似:
#ifdef LINUX_KEY_WORD
... // linux代码到这里。
#elif WINDOWS_KEY_WORD
... // windows代码到这里。
#else
#error操作系统不支持!
#endif
解决方案使用:
#ifdef __linux__
// linux代码到这里
#elif _WIN32
// windows代码在这里
#else
#endif
I want to run some c++ code on Linux and Windows. There are some pieces of code that I want to include only for one operating system and not the other. Is there a standard #ifdef that once can use?
Something like:
#ifdef LINUX_KEY_WORD ... // linux code goes here. #elif WINDOWS_KEY_WORD ... // windows code goes here. #else #error "OS not supported!" #endif
The question is indeed a duplicate but the answers here are much better, especially the accepted one.
解决方案use:
#ifdef __linux__ //linux code goes here #elif _WIN32 // windows code goes here #else #endif
这篇关于在Windows和Linux上的C ++编译:ifdef switch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!