I'm implementing on some C++ code that I would like to make as portable as possible. I would like to avoid dependencies on libraries that require root access to install. Further, I'd prefer to avoid keeping copies of large libraries in my repository, and I would also prefer not to do user-level installations of libraries (simply because I'd have to manually install them on multiple computers.)
I would like to use the normal_distribution
functionality from Boost in my project. I understand that the typical way to install Boost requires a sudo apt-get
or sudo yum
type of command, but I don't have root access on the systems where this code will run. To get around this, I'm wondering if I could simply place a copy of Boost's normal_distribution.cpp and normal_distribution.hpp in my code directory and compile/link my code with these files. Would this work?
Readers may wonder why I'm not just using the normal_distribution
implementation in TR1 or C++11. The answer is that I need to maintain compatibility with some university-managed clusters that still run g++ 4.1.x, which (at least in my experience) doesn't support <TR1/random>
.
I imagine that BCP (Boost Copy) was written precisely with your situation in mind.
I had some trouble getting BCP to work properly. I documented the BCP-related question in this StackOverflow post.
For the short term, I just added a
normal_distribution
function to my codebase. I put it together from a couple of past StackOverflow posts. This implementation doesn't do any fancy template stuff, but it otherwise looks pretty similar to the Boost, TR1, and C++11 APIs ofnormal_distribution
.Thanks to this StackOverflow post (user Pete855217) for the
sampleNormal()
function, and thanks to this StackOverflow post (user5084) for the function that I've namednormal_distribution()
.You should check out the ryppl project as this is exactly what it is hoping to achieve. If you follow the links to github you will find modularised boost and from there you may go on and try a full ryppl install. In any case there is a half way house and that is modularised boost. There is also a modularised boost/cmake to make it simpler. This is the direction ryppl is looking to take boost and it should be very helpful. The only downside I can see is the propensity to use python scripts for the zero install installer.
As stated BCP was developed for this purpose as well so there is a choice. Be aware though boost is going through a svn->git change and this seems to be affecting some structure which is reflected in some inconsistencies with the current modularised boost, I am not sure how/if that affects BCP as I have no knowledge of that system.