如何检查OS用preprocessor指令? [英] How do I check OS with a preprocessor directive?
本文介绍了如何检查OS用preprocessor指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要我的code做基础的操作系统,它被编上不同的东西。我正在寻找这样的事情:
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
//define something for Windows
#else
//define it for a Unix machine
#endif
有没有办法做到这一点?有没有更好的方式做同样的事情?
Is there a way to do this? Is there a better way to do the same thing?
推荐答案
有由大多数编译器使用predefined宏的您可以在这里找到列表
There are predefined macros that are used by most compilers, you can find the list here
否则,你将不得不调整构建系统让喜欢OS_WINDOWS / OS_UNIX宏编译时被定义,那么你将不得不使用IFDEF检查它在code。
Otherwise, you will have to adjust the build system so a macro like OS_WINDOWS/OS_UNIX gets defined during compilation, then you will have to check it in the code using ifdef.
#ifdef OS_WINDOWS
//define something for Windows
#else
//define it for a Unix machine
#endif
这篇关于如何检查OS用preprocessor指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文