我正在尝试让英特尔 C++ 编译器使用不同于编译器默认库的标准库 C++ header 。不幸的是,编译器默认使用的 header 没有定义我需要的特定类型特征/函数。
$ icpc --version
icpc (ICC) 16.0.2 20160204
Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
我想使用的 header 位于
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"
(这里我认为编译器使用它的默认 header 位置)或
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++ header ,因为我猜 -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 header 不支持 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++ header 的位置。
关于c++ - 在英特尔编译器中使用不同的标准 C++ 库 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37122526/