Roman - 1 year ago 56

C++ Question

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`

`locate poisson.hpp`

`/opt/software/boost/1.45_ubuntu12.4lts_gcc4.5.3/include/boost/math/distributions/poisson.hpp`

`#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 there a way to force the compiler to search the files in the correct directory?

I use

`g++`

Answer Source

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.