c++ - ICPC: "identifier "_Node_allocator"未定义"使用 std::map 和 icpc 编译 C++ 文件时

标签 c++ stl undefined-reference stdmap icc

我正在尝试编译以下代码:

#include <map>

int main() {
  std::map<double, double> test;

  return 0;
}

使用以下命令:

icpc -I /usr/include/x86_64-linux-gnu/c++/8  main.cpp -o test

我收到以下错误:

/usr/include/c++/8/bits/stl_tree.h(700): error: identifier 
"_Node_allocator" is undefined
            _GLIBCXX_NOEXCEPT_IF(

            ^
          detected during instantiation of "std::_Rb_tree<_Key, _Val, 
_KeyOfValue, _Compare, _Alloc>::_Rb_tree_impl<_Key_compare, 
<unnamed>>::_Rb_tree_impl() [with _Key=double, _Val=std::pair<const 
double, double>, _KeyOfValue=std::_Select1st<std::pair<const double,double>>, _Compare=std::less<double>, Alloc=std::allocator<std::pair<const double, double>>,_Key_compare=std::less<double>, <unnamed>=true]"
at line 6 of "main.cpp"

连同一些类型特征错误,如下所示:
/usr/include/c++/8/type_traits(921): error: not a class or struct name
      : public __is_default_constructible_atom<_Tp>::type
               ^
          detected during:
            instantiation of class 
"std::__is_default_constructible_safe<_Tp, false> [with _Tp=<error-
type>]" at line 927
            instantiation of class "std::is_default_constructible<_Tp> 
[with _Tp=<error-type>]" at line 144
            instantiation of class "std::__and_<_B1, _B2> [with 
_B1=std::is_default_constructible<<error-type>>, 
_B2=std::__is_nt_default_constructible_impl<<error-type>, false>]" at 
line 995
            instantiation of class 
"std::is_nothrow_default_constructible<_Tp> [with _Tp=<error-type>]" 
at line 700 of "/usr/include/c++/8/bits/stl_tree.h"
            instantiation of "std::_Rb_tree<_Key, _Val, _KeyOfValue, 
_Compare, _Alloc>::_Rb_tree_impl<_Key_compare, 
<unnamed>>::_Rb_tree_impl() [with _Key=double, _Val=std::pair<const 
double, double>, _Key
OfValue=std::_Select1st<std::pair<const double, double>>, 
_Compare=std::less<double>, _Alloc=std::allocator<std::pair<const 
double, double>>, _Key_compare=std::less<double>, <unnamed>=true]" at 
line 6 of "
main.cpp"

这段代码使用 g++ 编译没有问题。

icpc 和 g++ version 命令的结果如下:

> icpc -v
icpc version 18.0.3 (gcc version 8.1.0 compatibility)

> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
8.1.0-5ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-
8/README.Bugs --enable-
languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --
with-gcc-major-version-only --program-suffix=-8 --program-
prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --
libexecdir=/usr/lib --without-included-gettext --enable-
threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --
enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-
time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-libmpx --enable-plugin --with-
system-zlib --with-target-system-zlib --enable-objc-gc=auto --
enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-
tune=generic --enable-offload-targets=nvptx-none --without-cuda-
driver --enable-checking=release --build=x86_64-linux-gnu --
host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.1.0 (Ubuntu 8.1.0-5ubuntu1~16.04) 

所以我的icpc和g++版本是兼容的。我也没有忘记来源 compilervars.sh icpc 的文件。

我找不到任何有此错误的帖子,英特尔网站上也找不到。是否有特定的库需要添加到 icpc 中而不是自动添加才能使用 std::map ?

我试过添加 -lstdc++我自己在编译命令中,但这不起作用。

最佳答案

问题由 someone on the intel forums 回答:

即使使用以下 bash 命令,icc 18.0.3 也不支持 gcc-8:

> icpc -v
icpc version 18.0.3 (gcc version 8.1.0 compatibility)

让它看起来确实如此。

icc 18 支持 gcc 4.3 到 6.3。

为了在不更改默认 gcc 版本的情况下解决此问题,我执行了以下操作:

首先,我在 Ubuntu 16.04 机器上安装了 gcc 6:
sudo apt-get install gcc-6 g++-6

然后我将以下标志添加到我的编译器标志中:
-gxx-name=/usr/bin/g++-6

并将包含目录的版本更改为 6 而不是 8:
-I /usr/include/x86_64-linux-gnu/c++/6

关于c++ - ICPC: "identifier "_Node_allocator"未定义"使用 std::map 和 icpc 编译 C++ 文件时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51171206/

相关文章:

c++ - Python ImportError - undefined symbol - 用于自定义 C++ 模块

c++ - 为什么 MSVC _count_of 实现将 0 添加到 sizeof 的结果中?

c++ - 如何使用 std::sort 对数组中的特定对象进行排序?

c++ - 我应该更喜欢迭代器而不是 const_iterators 吗?

c++ - 使用连续无符号整数列表初始化 std::vector<unsigned int>

C 包含库失败

c++ - 为什么模板只能在头文件中实现?

c++ - 在 unordered_map 中分配或插入类对象

c++ - 使用第三方库 (sbpl)

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?