简体   繁体   English

使用#ifdef检测编译器

[英]Detect compiler with #ifdef

I'm trying to build a small code that works across multiple platforms and compilers. 我正在尝试构建一个适用于多个平台和编译器的小代码。 I use assertions, most of which can be turned off, but when compiling with PGI's pgicpp using -mp for OpenMP support, it automatically uses the --no_exceptions option: everywhere in my code with a "throw" statement generates a fatal compiler error. 我使用断言,其中大部分可以被关闭,但与PGI的编译时pgicpp使用-mp用于支持OpenMP,它会自动使用--no_exceptions选项:无处不在我的代码以“扔”语句生成一个致命编译器错误。 ("support for exception handling is disabled") (“禁用异常处理支持”)

Is there a define d macro I can test to hide the throw statements on PGI? 是否有一个define d宏我可以测试隐藏PGI上的throw语句? I usually work with gcc, which has GCC_VERSION and the like. 我通常使用gcc,它有GCC_VERSION等。 I can't find any documentation describing these macros in PGI. 我在PGI中找不到任何描述这些宏的文档。

Take a look at the Pre-defined C/C++ Compiler Macros project on Sourceforge. 查看Sourceforge上的预定义C / C ++编译器宏项目。

PGI's compiler has a __PGI macro. PGI的编译器有一个__PGI宏。

Also, take a look at libnuwen's compiler.hh header for a decent way to 'normalize' compiler versioning macros. 另外,看一下libnuwen的 compiler.hh头文件,以便“标准化”编译器版本控制宏。

You could try this to see what macros are predefined by the compiler: 您可以尝试这样来查看编译器预定义了哪些宏:

pgcc -dM

Maybe that will reveal a suitable macro you can use. 也许这将揭示你可以使用的合适的宏。

Have you looked at the boost headers? 你看过boost标题了吗? Supposing they support PGI, they will have found a way to detect it. 假设他们支持PGI,他们将找到一种方法来检测它。 You could use that. 你可以用它。 I would start to search somewhere in boost/config . 我会开始在boost/config搜索某个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM