Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using different Standard C++ library headers with Intel compiler

Tags:

c++

c++11

icc

I am trying to have the Intel C++ compiler use different standard library C++ headers than the compiler's default ones. 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)

The test.cc program just exercises the C++11 standard library feature that I'd need:

// 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. That's why I try to use the GCC ones' which do support it.

$ 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
                  ^
like image 359
ritter Avatar asked May 09 '16 18:05

ritter


1 Answers

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.

like image 108
ritter Avatar answered Nov 05 '22 16:11

ritter