Reputation: 102346
I seem to be missing something here. I moved from boost::shared_ptr
to std::shared_ptr
. shared_ptr
was part of TR1 back in the mid-2000s, and it should be available everywhere in 2012.
Trying to use shared_ptr
under Apple gets me a slew of undefined references:
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;
A typical compiler command is as follows (both GCC and Clang fail):
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
I'm trying to include it as follows (I believe I need to tweak this, but I don't recall the C++ syntax to say "look here, or look there"):
#include <memory>
using std::shared_ptr;
using std::tr1::shared_ptr;
Apple's man pages are not turning up anything:
$ man shared_ptr
No manual entry for shared_ptr
$ man -k shared_ptr
shared_ptr: nothing appropriate
I have Mac OS X 10.8 (fully patched), Xcode (fully patched), and Command Line Tools installed.
So how does one use a std::shared_ptr on Apple platforms?
Upvotes: 15
Views: 11049
Reputation: 8932
#include <tr1/memory>
will work with either compiler using libstdc++. Alternately, with Clang:
#include <memory>
using std::shared_ptr;
and compile with c++ -std=c++11 -stdlib=libc++ ...
. I have no idea why Clang is using libstdc++ by default; presumably it's for GCC compatibility.
You can't find the man pages because libstdc++ doesn't have man pages. Helpful, isn't it. There's HTML documentation in the source distribution.
Upvotes: 22