Possible Duplicate:
Building a subset of boost in windows
I'm using Visual c++ 6.0, and I'd like to use boost::random. I can't find any examples showing how I would go about just using this and only this library. Can I just include it in my source?
Possible Duplicate:
Building a subset of boost in windows
I'm using Visual c++ 6.0, and I'd like to use boost::random. I can't find any examples showing how I would go about just using this and only this library. Can I just include it in my source?
Yes, to use
boost::random
, you can simply include the header in your source file.Since Boost uses templates extensively, many of the libraries are implemented purely in headers (and template implementation files, a la
txx
).Most of the libraries are also independent, so you can use just one without depending on another. (Exceptions are documented.)
If you look at the list of Boost libraries you will see many of them labelled "Header only", so there is no additional library to link against.
Yes, most boost libraries are header only so you do not need to compile any source files.
Most of boost is distributed as "header only" libraries - meaning you do not need to "build" any kind thing to use that library. Random is one of those, so it is possible to just include the correct header files and you will be away laughing. I would say it is best to get the whole boost source somewhere, and reference that since the different parts tend to have some dependencies on each other.
The only thing to be careful about is to add the path to boost in your include path. Even though the libraries are headers only, many boost headers include other headers in the boost library and won't be able to find them if you don't have the include path set up correctly.
My current project has this include path:
My code then includes boost headers like this:
boost/random.hpp has a bunch of lines like #include "boost/random/linear_congruential.hpp", which is why you need the include path.
I am not sure what your concern is here. Even if you included other headers, and/or linked other libraries, your final executable will include only those parts of the library needed to resolve symbols in your code. It will not throw in unused object modules. Inlined code and templates in headers are not instantiated unless they are referenced.
Since Boost is primarily a template library and to work around lack of template awareness in most linkers, the code is inlined in the header file, the instantiated templates are compiled into the each object module in which it is instantiated. So you may end up with duplicate code in multiple modules, which if executable size if your concern, you should perhaps be aware of.
Boost got a very nice tool called bcp which does what you want. check it out.
from the docs: