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
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.