【问题标题】:How to detect Intel's compiler (ICC) with ifdef?如何使用 ifdef 检测 Intel 的编译器 (ICC)?
【发布时间】:2012-11-23 18:11:47
【问题描述】:

我想在 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

【问题讨论】:

  • 出于好奇,你为什么需要那个宏?
  • @delnan:确实,如果你需要像这样定义INLINE,听起来你做错了什么......
  • 是的,icc 定义了__GNUC__,因为__GNUC__ 并不意味着“我是GCC”;它的意思是“我是 'GNU C' 语言(标准 C 的超集)的编译器”。
  • 关于 ICC 与 GCC 的兼容性,您可能想在这里阅读:software.intel.com/sites/products/collateral/hpc/compilers/…
  • 我将它用于复杂的数字。根据我阅读的内容,如果这些语句是明确的,编译器会更加努力地内联函数。请注意,我知道告诉编译器有关内联的不同方法。事实上,我最初在 3.x 版本中将它与 gcc 一起使用,它曾经非常相关。

标签: c macros c-preprocessor intel icc


【解决方案1】:

__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 
    

    【讨论】:

    • 你应该在你的答案中添加重要的部分,以防有一天链接失效。
    • 我打算使用std::endl 分别刷新每一行(而不是简单的'\n')来抱怨您的回答,但是这个问题存在于您从中获得示例的英特尔原件中。 ://
    猜你喜欢
    • 2010-11-17
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    相关资源
    最近更新 更多