Detect compiler with #ifdef

一个人想着一个人 提交于 2019-12-17 19:59:10

问题


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")

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.


回答1:


Take a look at the Pre-defined C/C++ Compiler Macros project on Sourceforge.

PGI's compiler has a __PGI macro.

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




回答2:


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.




回答3:


Have you looked at the boost headers? Supposing they support PGI, they will have found a way to detect it. You could use that. I would start to search somewhere in boost/config.



来源:https://stackoverflow.com/questions/1233435/detect-compiler-with-ifdef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!