Canot 编译C++它使用了来自 boost 的 odeint

Canot compile C++ which uses odeint from boost

本文关键字:boost odeint 编译 C++ Canot      更新时间:2023-10-16

我在 Ubuntu 12.04 上,并且在/usr/include 中已经有一些提升功能。我做了一个

sudo apt-get install libboost-all-dev

这也安装了很多文件。我不想删除此提升并从源代码安装,因为其他几个软件包依赖于 ubuntu 存储库中的版本。这是我想要运行的示例代码:-

#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;
    }
}

在第一次编译g++ -o test test.cpp时,它抛出了一个错误 /usr/include/boost/numeric/odeint.hpp permission denied

所以我使用

sudo chmod -R +x odeint/

这一次,它没有说权限被拒绝,而是抛出了 400 行错误,如下所示 - 来自终端的错误日志>

如何编译?文档中或其他任何地方都没有 odeint 的安装指南

boost的这一部分似乎使用了C++11功能。因此,您需要将-std=c++0x-std=c++11添加到编译器调用中。

随后的错误test.cpp: In function ‘int main()’: test.cpp:30:5: error: ‘stepper_euler’ was not declared in this scope指向另一个错误源:您忘记包含声明stepper_euler的文件。将适当的#include <file>放在代码的开头。