在OS X 10.9.3上使用Xcode 5.1.1编译unordered_map失败

时间:2014-07-14 20:47:29

标签: c++ xcode macos templates c++11

我正在尝试编译最初使用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;

我能够找到针对类似问题(https://issues.apache.org/ooo/show_bug.cgi?id=124422)的Apache OpenOffice的错误报告,但是无法使用它来解决我的问题。如果有人有任何想法我会非常感激。

1 个答案:

答案 0 :(得分:2)

您在分配器(第二个)中错过了一个讨厌的const

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