[英]Using different Standard C++ library headers with Intel compiler
I am trying to have the Intel C++ compiler use different standard library C++ headers than the compiler's default ones. 我试图让英特尔C ++编译器使用不同于编译器默认的标准库C ++标头。 The headers that the compiler would use per default unfortunately do not define a particular type trait/function that I need. 遗憾的是,编译器默认使用的标头不会定义我需要的特定类型特征/功能。
$ icpc --version
icpc (ICC) 16.0.2 20160204
Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
The headers I'd like to use are located in 我想要使用的标题位于
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
But whatever I try, I either get 但无论我尝试什么,我都会得到
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"
(here I think the compiler uses it's default header location) or (这里我认为编译器使用它的默认标头位置)或
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
(here it doesn't use any C++ headers at all, because the -nostdinc++ flag disables it all together, I guess) (这里根本不使用任何C ++标头,因为-nostdinc ++标志一起禁用它,我猜)
The test.cc program just exercises the C++11 standard library feature that I'd need: 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;
}
EDIT: 编辑:
Just to be sure to have this properly motivated. 只是为了确保这有正确的动机。 The default C++11 headers on this system do not support the std::declval. 此系统上的默认C ++ 11标头不支持std :: declval。 That's why I try to use the GCC ones' which do support it. 这就是为什么我尝试使用那些支持它的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
^
Found it! 找到了!
icpc -std=c++11 -o tes test.cc -cxxlib=/opt/crtdc/gcc/4.8.5-4/
The Intel compiler expects the executable bin/gcc to be present in that path and queries the location for the C++ headers using this executable. 英特尔编译器期望可执行文件bin / gcc存在于该路径中,并使用此可执行文件查询C ++标头的位置。
Compilers and their standard libraries are pretty tightly bound. 编译器及其标准库非常紧密。 I doubt you'll get anywhere with this endevour. 我怀疑你会得到这种努力的任何地方。
Use a different compiler/std lib or poke Intel to fix their implementation, then upgrade. 使用不同的编译器/ std lib或戳英特尔来修复它们的实现,然后升级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.