I work on a cross-platform (Windows, Linux, Solaris) project. I want to use Boost's shared_ptr in this project.
How can I install it, and redistribute it with the project to the customers?
I don't have root permissions on Linux/Solaris, so I probably have to add Boost' sources to my sources, and build it together.
Also,开发者_运维问答 our version of Solaris is very old (2.5.1, May 1996). Can it cause any problem with the building of shared_ptr?
Just install the boost header files (you don't need to compile and install the libraries for shared_ptr, because it's header only). Don't forget to check if the include paths for boost are set up right inside your IDE, so it will be able to find the header file.
In your code file, include this header:
#include<boost/shared_ptr.hpp>
and use it like this:
boost::shared_ptr<int> ptrToInt (new int);
There's no need to include sources of the Boost library (Boost is a pretty big library). Just include Boost in your prerequisites.
In case if you redistribute your project in binary form you don't need to include Boost libraries at all.
boost::shared_ptr
is header-only. Just add the necessary header file(s) to your project and you are done.
shared_ptr
is also part of TR1, the first C++ Library Technical Report and is e.g. included in newer versions of GCC (>= 4.0.0) (see here for further information).
You don't need much of the boost library just to use shared_ptr. Use the bcp tool to extract just the bits that shared_ptr depends on, which may be preferable to installing the full library.
精彩评论