Apple and shared_ptr

Apple and shared_ptr

本文关键字:ptr shared and Apple      更新时间:2023-10-16

我似乎在这里错过了一些东西。我从boost::shared_ptr搬到了std::shared_ptr. 早在 2000 年代中期,shared_ptr 就是 TR1 的一部分,2012 年应该可以在任何地方使用。

尝试在Apple下使用shared_ptr会给我带来大量未定义的引用:

SecureArray.h:26:12: error: no member named 'shared_ptr' in
      namespace 'std'
using std::shared_ptr;
      ~~~~~^
SecureArray.h:27:12: error: no member named 'tr1' in namespace
      'std'
using std::tr1::shared_ptr;
      ~~~~~^
SecureArray.h:487:5: error: unknown type name 'shared_ptr'
    shared_ptr<SecureVector> m_vector;

典型的编译器命令如下(GCC 和 Clang 都失败):

clang++ -g2 -ggdb -O0 -fcatch-undefined-cxx0x-behavior
  -DSAFEINT_DISALLOW_UNSIGNED_NEGATION=1 -pipe -std=c++0x -Wall -Wextra
  -Wno-unused-parameter -Wno-tautological-compare 
  -I. -I./esapi -I./deps -I/usr/local/include -I/usr/include -fpic
  -c src/DummyConfiguration.cpp -o src/DummyConfiguration.o

我试图将其包含如下(我相信我需要调整它,但我不记得C++语法说"看这里,或看那里"):

#include <memory>
using std::shared_ptr;
using std::tr1::shared_ptr;

苹果的手册页没有出现任何东西:

$ man shared_ptr
No manual entry for shared_ptr
$ man -k shared_ptr
shared_ptr: nothing appropriate

我安装了Mac OS X 10.8(完全修补),Xcode(完全修补)和命令行工具。

那么如何在苹果平台上使用std::shared_ptr呢?

#include <tr1/memory>将使用libstdc++与任一编译器一起使用。或者,与叮当:

#include <memory>
using std::shared_ptr;

并使用c++ -std=c++11 -stdlib=libc++ ...编译.我不知道为什么 Clang 默认使用 libstdc++;大概是为了 GCC 兼容性。

找不到手册页,因为 libstdc++ 没有手册页。有帮助,不是吗。源代码分发中有 HTML 文档。