0

I'm on Ubuntu 12.04 & had some boost fies already in /usr/include. I did a

sudo apt-get install libboost-all-dev

and that installed a lot of files too. I don't want to remove this boost and install from source as several other packages depend on the version from the ubuntu repos. This is the sample code I want to run :-

#include <iostream>
#include <boost/numeric/odeint.hpp>



using namespace std;
using namespace boost::numeric::odeint;

typedef vector< double > state_type;

const double sigma = 10.0;
const double R = 28.0;
const double b = 8.0 / 3.0;

void lorenz( state_type &x , state_type &dxdt , double t )
{
    dxdt[0] = sigma * ( x[1] - x[0] );
    dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
    dxdt[2] = x[0]*x[1] - b * x[2];
}

int main()
{
    const double dt = 0.01;

    state_type x(3);
    x[0] = 1.0 ;
    x[1] = 0.0 ;
    x[2] = 0.0;
    stepper_euler< state_type > stepper;
    stepper.adjust_size( x );

    double t = 0.0;
    for( size_t oi=0 ; oi<10000 ; ++oi,t+=dt )
    {
        stepper.do_step( lorenz , x , t , dt );
        cout << x[0] << " " << x[1] << " " << x[2] << endl;
    }
}

ON first compile g++ -o test test.cpp, it threw an error /usr/include/boost/numeric/odeint.hpp permission denied

So I changed the file permission of all odeint files recursively using

sudo chmod -R +x odeint/

This time, it did not say permission denied but threw 400 lines of error as can be seen here -> error log from terminal

How do I compile it ? There are no install guides for odeint in the documentation or anywhere else

  • First of all: Does the file exist? – stefan Nov 09 '13 at 11:47
  • Yes, all required files exist –  Nov 09 '13 at 11:49
  • Can it be that odeint is not compatible with the version of boost from ubuntu repos and that there is no alternative but to install the latest boost from source which ships odeint by default ? –  Nov 09 '13 at 11:51
  • Then start with the first error listed in the log: `/usr/include/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp:307:42: error: ‘bind’ is not a member of ‘boost::numeric::odeint::detail’`. Make sure it actually is the first one. You can compile with `-Wfatal-errors` to abort on first error. – stefan Nov 09 '13 at 11:51
  • @stefan With the -Wfatal-errors flag it gives :- 'In file included from /usr/include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp:25:0, from /usr/include/boost/numeric/odeint/stepper/euler.hpp:23, from /usr/include/boost/numeric/odeint.hpp:27, from test.cpp:2: /usr/include/boost/numeric/odeint/util/bind.hpp:44:14: error: ‘std::bind’ has not been declared compilation terminated due to -Wfatal-errors' –  Nov 09 '13 at 11:54
  • Try compiling with `-std=c++0x` or `-std=c++11`. – stefan Nov 09 '13 at 11:55
  • @stefan Actually i want to compile using nvcc down the line, which strips and passes the C++ only part to gcc, but again no luck with -std=c++0x either –  Nov 09 '13 at 11:57
  • Well but does it display another error? By the way: What compiler version do you use? Execute `g++ -v`. – stefan Nov 09 '13 at 11:58
  • gcc version 4.6.3 and it threw this with -std=c++0x `test.cpp: In function ‘int main()’: test.cpp:30:5: error: ‘stepper_euler’ was not declared in this scope compilation terminated due to -Wfatal-errors.` –  Nov 09 '13 at 12:02
  • Well then fix this issue. I don't know where `stepper_euler` is declared. Find it and include the appropriate header. – stefan Nov 09 '13 at 12:03
  • can you try to compile it, with adding -std=c++0x option to gcc ? which version of gcc do you use ? – iyasar Nov 09 '13 at 12:05
  • @iyasar I did, please refer previous comments –  Nov 09 '13 at 12:10
  • There is no stepper 'stepper_euler' in odeint. I guess the example you are using is from an old version of odeint. Which boost version is installed? Have you used odeint from the git repository or from boost? – headmyshoulder Nov 09 '13 at 13:56
  • @headmyshoulder My vanilla Ubuntu 12.04 install did not have odeint in the boost/numeric folder. So I downloaded odeint from github and did sudo cp to the required boost path –  Nov 09 '13 at 16:24

1 Answers1

1

This part of boost seems to use C++11 features. Therefore you need to add either -std=c++0x or -std=c++11 to your compiler invocation.

The subsequent error test.cpp: In function ‘int main()’: test.cpp:30:5: error: ‘stepper_euler’ was not declared in this scope points you to another source of error: You forgot to include the file in which stepper_euler is declared. Put the appropriate #include <file> at the beginning of your code.

stefan
  • 10,215
  • 4
  • 49
  • 90
  • @headmyshoulder The compiler error the OP provided in the comments suggests otherwise. It seems to use `std::bind` which is C++11. – stefan Nov 09 '13 at 13:50
  • I am sure that it works without C++11 (I am one of the authors). There are preprocessor macros checking if C++11 is enabled. If it is, it uses std::bind, other boost::bind. – headmyshoulder Nov 09 '13 at 13:54
  • @headmyshoulder it might be the users fault that `std::bind` is used (and not available because of missing `-std=c++0x`), but from what the OP shows, this seems unlikely. I suspect a bug in the logic deciding for `boost::bind`. – stefan Nov 09 '13 at 13:56
  • headmyshoulder & /stefan, both are right. odeint is incompatible with the boost ver[1.42] on ubuntu repos. I got the latest boost from sourceforge & built the entire thing. Then followed stefan's advice and it compiled. The example posted is of an older odeint version as @headmyshoulder pointed out correctly.`g++ -o example -std=c++0x -Wfatal-errors example.cpp` Getting NVIDIA's CUDA compiler to behave was a tiny bit trickier, `nvcc -o example -Xcompiler "-std=c++0x" example.cpp` C++11 enabling is a necessity and AFAIK only available with CUDA toolkit 5.5. Thanks for your help folks :) –  Nov 09 '13 at 16:33