繁体   English   中英

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

[英]Using different Standard C++ library headers with Intel compiler

我试图让英特尔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
                  ^

找到了!

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

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

编译器及其标准库非常紧密。 我怀疑你会得到这种努力的任何地方。

使用不同的编译器/ std lib或戳英特尔来修复它们的实现,然后升级。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM