用#ifdef检测编译器 [英] Detect compiler with #ifdef

查看:179
本文介绍了用#ifdef检测编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个可以跨多个平台和编译器工作的小代码。我使用断言,其中大部分可以关闭,但当用PGI的 pgicpp 使用 -mp 为OpenMP支持,它会自动使用 - no_exceptions 选项:在我的代码中使用throw语句生成一个致命的编译器错误。 (支持异常处理被禁用)

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. ("support for exception handling is disabled")

有一个 define d宏我可以测试隐藏 throw 语句在PGI?我通常使用gcc,它具有 GCC_VERSION 等。我在PGI中找不到任何描述这些宏的文档。

Is there a defined macro I can test to hide the throw statements on PGI? I usually work with gcc, which has GCC_VERSION and the like. I can't find any documentation describing these macros in PGI.

推荐答案

看看在Sourceforge上预先定义的C / C ++编译器宏项目。

PGI的编译器有一个 __ PGI 宏。

PGI's compiler has a __PGI macro.

另请参阅 libnuwen的 compiler.hh头文件,以便正常化编译器版本控制宏。

Also, take a look at libnuwen's compiler.hh header for a decent way to 'normalize' compiler versioning macros.

这篇关于用#ifdef检测编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆