【问题标题】:Using different Standard C++ library headers with Intel compiler通过英特尔编译器使用不同的标准 C++ 库头文件
【发布时间】:2016-09-04 11:41:30
【问题描述】:

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

【问题讨论】:

  • 我怀疑这是一项富有成效的练习。我很害怕标准库可以在它的编译器之外使用的日子已经一去不复返了——现在有太多的编译器内在。但是你需要什么类型的特征?

标签: c++ c++11 icc


【解决方案1】:

编译器和它们的标准库绑定得非常紧密。我怀疑你会通过这种努力取得任何进展。

使用不同的编译器/标准库或戳 Intel 修复它们的实现,然后升级。

【讨论】:

  • 英特尔编译器是个例外。它们旨在与 Linux 上的 GCC 工具链(以及 Windows 上的 MS 工具链)兼容,包括 stdc++。
  • ...和 ​​Mac 上的 LLVM 编译器工具链。
【解决方案2】:

找到了!

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

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

【讨论】:

  • 从手册页中找到这些信息并不容易。所以很高兴在 SO 上有这个
  • 遗憾的是,此选项在 Intel 17 (icpc: command line warning #10006: ignoring unknown option '-cxxlib=/usr/local/Cellar/llvm/4.0.0') 中已被弃用,或者至少这是我在 Mac 上看到的。
猜你喜欢
  • 2020-02-05
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
  • 2023-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-21
相关资源
最近更新 更多