在英特尔编译器中使用不同的标准C ++库头

时间:2016-05-09 18:05:55

标签: c++ c++11 icc

我正在尝试让英特尔C ++编译器使用与编译器默认编译器不同的标准库C ++标头。遗憾的是,编译器默认使用的标头不会定义我需要的特定类型特征/函数。

$ icpc --version
icpc (ICC) 16.0.2 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

我想使用的标题位于

ls /opt/crtdc/gcc/4.8.5-4/include/c++/4.8.5/:

algorithm  cfenv      condition_variable  cstring    ext               iostream  numeric           sstream       tuple
array      cfloat     csetjmp             ctgmath    fenv.h            istream   ostream           stack         typeindex
atomic     chrono     csignal             ctime      forward_list      iterator  parallel          stdexcept     typeinfo
backward   cinttypes  cstdalign           cwchar     fstream           limits    profile           streambuf     type_traits
bits       ciso646    cstdarg             cwctype    functional        list      queue             string        unordered_map
bitset     climits    cstdbool            cxxabi.h   future            locale    random            system_error  unordered_set
cassert    clocale    cstddef             debug      initializer_list  map       ratio             tgmath.h      utility
ccomplex   cmath      cstdint             decimal    iomanip           memory    regex             thread        valarray
cctype     complex    cstdio              deque      ios               mutex     scoped_allocator  tr1           vector
cerrno     complex.h  cstdlib             exception  iosfwd            new       set               tr2           x86_64-redhat-linux

但无论我尝试什么,我要么

icpc -std=c++11 -o test test.cc -Qlocation,cxxinc,/opt/crtdc/gcc/4.8.5-4/include/c++/4.8.5/

error: namespace "std" has no member "declval"

(这里我认为编译器使用它的默认标头位置)或

icpc -std=c++11 -o test test.cc -nostdinc++ -Qlocation,cxxinc,/opt/crtdc/gcc/4.8.5-4/include/c++/4.8.5/

test.cc(2): catastrophic error: cannot open source file "utility"
  #include <utility>      // std::declval

(这里根本不使用任何C ++标头,因为-nostdinc ++标志一起禁用它,我猜)

test.cc程序只是运用我需要的C ++ 11标准库功能:

// declval example
#include <utility>      // std::declval
#include <iostream>     // std::cout

struct A {              // abstract class
  virtual int value() = 0;
};

class B : public A {    // class with specific constructor
  int val_;
public:
  B(int i,int j):val_(i*j){
    std::cout << "ctor\n";
  }
  int value() {return val_;}
};

int main() {
  decltype(std::declval<A>().value()) a;  // int a
  decltype(std::declval<B>().value()) b;  // int b
  decltype(B(0,0).value()) c;   // same as above (known constructor)
  a = b = B(10,2).value();
  std::cout << a << '\n';
  return 0;
}

修改

确保有正确的动力。此系统上的默认C ++ 11标头不支持std :: declval。这就是为什么我尝试使用那些支持它的GCC。

$ icpc -std=c++11 -o test test.cc
opa.cc(19): error: namespace "std" has no member "declval"
    decltype(std::declval<A>().value()) a;  // int a
                  ^

2 个答案:

答案 0 :(得分:4)

发现它!

icpc -std=c++11 -o tes test.cc -cxxlib=/opt/crtdc/gcc/4.8.5-4/

英特尔编译器希望可执行文件bin / gcc出现在该路径中,并使用此可执行文件查询C ++标头的位置。

答案 1 :(得分:-1)

编译器及其标准库非常紧密。我怀疑你会在这个方面获得任何好处。

使用不同的编译器/标准库或推动英特尔修复其实施,然后升级。