I am trying to compile this small program:
#include <boost/math/distributions/poisson.hpp>
namespace boost { namespace math {
template <class RealType = double,
class Policy = policies::policy<> >
class poisson_distribution;
typedef poisson_distribution<> poisson;
template <class RealType, class Policy>
class poisson_distribution
{
public:
typedef RealType value_type;
typedef Policy policy_type;
poisson_distribution(RealType mean = 1); // Constructor.
RealType mean()const; // Accessor.
}
}} // namespaces boost::math
This code is taken from here.
The compiler tells me that boost/math/distributions/poisson.hpp
is not found. So, I try to find this file by myself (using locate poisson.hpp
command). I find the following file: /opt/software/boost/1.45_ubuntu12.4lts_gcc4.5.3/include/boost/math/distributions/poisson.hpp
. So, in my code I put the full name of the file to make sure that compiler finds it:
#include </opt/software/boost/1.45_ubuntu12.4lts_gcc4.5.3/include/boost/math/distributions/poisson.hpp>
But now I get another error message: boost/math/distributions/fwd.hpp
is not found.
Is there a way to force the compiler to search the files in the correct directory?
I use g++
compiler.
Boost can't be used with C as it uses OOP features from C++. It may be technically possible to develop a wrapper for it.
In the properties dialog, select "Configuration Properties" and then "VC++ Directories". You will need to add the Boost include path to the "Include Directories" list. If you're using all header-only libraries then you're done. Otherwise, you will need to add the Boost library path to "Library Directories".
Download either the zip or the 7zip package of boost. Extract the contents to extract_dir. If the minGW\bin folder (can be found in CodeBlocks installatoin folder) is not in the path variable add it. Open the file extract_dir\project-config.
You need an include path in your g++ command:
g++ -I/opt/software/boost/1.45_ubuntu12.4lts_gcc4.5.3/include/ [rest of command here]
(and possibly a link to a library path as well).
In general, it's not a good idea to put full paths in your source code; that kind of completely destroys the idea of portability :) (meaning, that code can no longer be compiled on any other PC in the world than your own, and even that is going to be dubious half a year from now).
Anyway, if you find yourself typing long compiler lines like the one above, it's really time to start using a makefile.
You'll probably find this question interesting as well.
(This isn't a direct answer to the question, but a list of considerations that I think should be addressed with the final and complete answer that @uoɥʇʎPʎzɐɹC wants to see here.)
The question of handling 3rd party dependencies with C++ isn't a simple one. There are many approaches for this and choosing the approach that is right for you depends on your toolset and environment, on your project management and on the trade-offs you want to take.
For Boost, we have to remember that it's mostly header-only library, but some components include a separately-compiled part too (can be static or dynamic lib, can be mandatory for the component or just for a specific use-case of it). E.g. Boost.Filesystem requires compilation, Boost.Graph requires it only if you want to parse GraphViz files and Boost.Variant doesn't need it at all (is "header-only" library). For details, see http://www.boost.org/doc/libs/release/more/getting_started/unix-variants.html#header-only-libraries (this redirects to the latest version, which is currently 1.61).
Using only header-only parts of Boost simplifies many of the considerations, but, of course, sometimes you need the other parts too.
Things to consider:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With