Compiling with separate Boost libraries, without installing Boost

I am using C ++ code, which I would like to make as portable as possible. I would like to avoid library dependencies that need root access to install. In addition, I would prefer not to store copies of large libraries in my repository, and I would also prefer not to install the library settings at the user level (simply because I would have to manually install them on multiple computers.)

I would like to use the functionality normal_distributionfrom Boost in my project. I understand that the typical way to install Boost requires a command such as sudo apt-getor sudo yum, but I do not have root access to the systems on which this code will be executed. To get around this, I am wondering if I can just put a copy of Boost normal_distribution.cpp and normal_distribution.hpp in my code directory and compile / link my code to these files. Will this work?

Readers may wonder why I'm not just using an implementation normal_distributionin 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) do not support <TR1/random>.

+5
source share
3 answers

I assume that BCP (Boost Copy) was written specifically for your situation.

+3
source

ryppl, , . github, , ryppl. , . boost/cmake, . , ryppl , . , , - python .

, BCP, . , svn → git, , , , , , / BCP, .

+2

BCP. fooobar.com/questions/1120940/....

normal_distribution . StackOverflow. - , API Boost, TR1 ++ 11 normal_distribution.

#include "math.h"
double normal_distribution(double mean, double stdDev)
{
    //scale the number to appropriate distribution 
    return mean + (sampleNormal()*stdDev);
}

//get a number from normal distribution (mean=0, stdDev=1). 
double sampleNormal() {
    double u = ((double) rand() / (RAND_MAX)) * 2 - 1;
    double v = ((double) rand() / (RAND_MAX)) * 2 - 1;
    double r = u * u + v * v;
    if (r == 0 || r > 1) return sampleNormal(); //recursively re-generate number if doesn't meet criteria
    double c = sqrt(-2 * log(r) / r);
    return u * c;
}

Thanks to fooobar.com/questions/59072 / ... (user Pete855217) for the function sampleNormal()and thanks fooobar.com/questions/59072 / ... (user5050) for the function that I called normal_distribution().

0
source

All Articles