在OS X 10.9.3的Xcode 5.1.1下,unordered_map编译失败

Compiling with unordered_map fails with Xcode 5.1.1 on OS X 10.9.3

本文关键字:unordered 1下 map 失败 编译 OS Xcode      更新时间:2023-10-16

我正在尝试编译一个最初使用tr1/unordered_map的项目。我已经删除了对tr1命名空间的所有引用,现在只是使用unordered_map(例如#include <tr1/unordered_map>变成#include <unordered_map>)。然而,我得到一个编译错误。在配置:

CXXR is now configured for x86_64-apple-darwin13.2.0
  Source directory:          .
  Installation directory:    /Library/Frameworks
  C compiler:                gcc  -g -O2 -fexceptions
  Fortran 77 compiler:       gfortran  -g -O2
  C++ compiler:              g++  -g -O2 -Wno-attributes -std=c++11
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:            gcc -g -O2 -fobjc-exceptions
  Interfaces supported:      X11, aqua, tcltk
  External libraries:        readline, ICU
  Additional capabilities:   PNG, JPEG, TIFF, NLS
  CR Options enabled:        framework, shared BLAS, R profiling
  CXXR Options enabled:      
  Recommended packages:      yes

当我尝试编译项目时,我遇到了错误:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/unordered_map:724:5: error: static_assert failed "Invalid allocator::value_type"
    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
Environment.cpp:104:5: note: in instantiation of template class 'std::__1::unordered_map<const CXXR::Symbol *, CXXR::Frame::Binding *, std::__1::hash<const CXXR::Symbol *>,
      std::__1::equal_to<const CXXR::Symbol *>, CXXR::Allocator<std::__1::pair<const CXXR::Symbol *, CXXR::Frame::Binding *> > >' requested here
    delete s_search_path_cache;

s_search_path_cache定义为:

typedef
std::unordered_map<const Symbol*, Frame::Binding*,
    std::hash<const Symbol*>,
    std::equal_to<const Symbol*>,
    CXXR::Allocator<std::pair<const Symbol*, Frame::Binding*> >
    > Cache;
static Cache* s_search_path_cache;

我能够找到一个bug报告给Apache OpenOffice类似的问题(https://issues.apache.org/ooo/show_bug.cgi?id=124422),但一直无法使用它来解决我的问题。如果有人有什么建议,我将不胜感激。

您的分配器中缺少一个讨厌的const(第二个):

CXXR::Allocator<std::pair<const Symbol* const, Frame::Binding*> >