如何使用ifdef检测Intel编译器(ICC)?

8

我希望在Linux上使用英特尔当前的编译器。我有一个内联宏,应该可以检测编译器。

过去的GCC和ICC版本都可以正常工作,但现在我用ICC会得到extern inline。ICC是否现在定义了__GNUC__?如何检测ICC或英特尔的C++编译器ICPC?

#ifndef INLINE
# if defined(__GNUC__) || defined(__GNUG__)
#  define INLINE extern inline
# else
#  define INLINE inline
# endif
#endif

3
出于好奇,你为什么需要那个宏呢? - user395760
@delnan:确实,如果您需要像那样定义“INLINE”,那么似乎您正在做一些错误的事情... - R.. GitHub STOP HELPING ICE
5
是的,ICC定义了__GNUC__因为__GNUC__并不意味着“我是GCC”,而是表示“我是一个‘GNU C’语言编译器(标准C的超集)”。 - R.. GitHub STOP HELPING ICE
关于ICC与GCC的兼容性,您可能会在这里阅读:http://software.intel.com/sites/products/collateral/hpc/compilers/intel_linux_compiler_compatibility_with_gnu_compilers.pdf - alk
旧版本的gcc(例如,gcc 2.95甚至某些gcc 3.x的版本)在某些情况下需要extern inline,但是对于最新版本的gcc,这种技巧应该是不必要的。 - Paul R
1
我正在使用它进行复杂的数字计算。根据我的阅读,编译器会更努力地尝试内联函数,如果这些语句是显式的话。请注意,我知道告诉编译器有关内联的不同方法。事实上,我最初在gcc 3.x版本中使用了这个,并且它曾经非常相关。 - highsciguy
2个回答

15

__INTEL_COMPILER 是您要寻找的内容。(来源:ICC man page)


2
以下网页显示如何检测最近的英特尔编译器的信息:

https://software.intel.com/content/www/us/en/develop/articles/use-predefined-macros-for-specific-code-for-intel-dpcpp-compiler-intel-cpp-compiler-intel-cpp-compiler-classic.html

编辑(这是网站上区分不同版本的代码):
// Predefined macros Intel® DPC++ Compiler
// dpcpp only
#if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for DPC++ compiler below
   // ... ...

  // example only
   std::cout << "SYCL_LANGUAGE_VERSION: " << SYCL_LANGUAGE_VERSION <<  std::endl;
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif


 //Predefined Macros for Intel® C++ Compiler
#if !defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for Intel C++ Compiler below
   // ... ...

   // example only
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif

// Predefined Macros for Intel® C++ Compiler Classic
// icc/icpc classic only
#if defined(__INTEL_COMPILER)
   // code specific for Intel C++ Compiler Classic below
   // ... ...

   // example only
   std::cout << "__INTEL_COMPILER_BUILD_DATE: " <<   _INTEL_COMPILER_BUILD_DATE << std::endl;
   std::cout << "__INTEL_COMPILER: " << __INTEL_COMPILER << std::endl;
  std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif 

你应该在回答中添加重要的部分,以防链接在未来失效。 - user694733
我本来想抱怨你的答案使用std::endl来分别刷新每一行(而不是简单的'\n'),但这个问题在英特尔的原始代码中也存在,你从中得到了这个例子。 :/ - Peter Cordes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接