c++ - 无法编译使用来自 boost 的 odeint 的 C++

标签 c++ ubuntu boost odeint

我在 Ubuntu 12.04 上并且在/usr/include 中已经有一些 boost fies。我做了一个

sudo apt-get install libboost-all-dev

而且还安装了很多文件。我不想删除此 boost 并从源代码安装,因为其他几个软件包取决于 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 权限被拒绝

所以我使用

递归地更改了所有 odeint 文件的文件权限
sudo chmod -R +x odeint/

这一次,它没有说权限被拒绝,而是抛出了 400 行错误,如下所示 -> error log from terminal

如何编译它?文档或其他任何地方都没有 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>在代码的开头。

关于c++ - 无法编译使用来自 boost 的 odeint 的 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19875527/

相关文章:

c++ - 链接器需要 lib 文件名称中的编译器和 Boost 版本。 fatal error LNK1104

c++ - 使用 boost::spirit 在 C++ 中读取二维数组

c++ - 关于多线程我应该了解什么以及何时使用它,主要是在c++中

c++ - 私有(private)对象指针与对象值,以及返回对象内部结构

tomcat - 无法在ubuntu中执行java类文件

linux - 在 Ubuntu 上暂时禁用 Gold Linker

c++ - 局部变量的内存被重新分配 - 为什么

c++ - 如何修复警告 "the compiler can assume that the address of ' 对象“永远不会为 NULL”

python - 在交互式 Python Shell 中实例化一个类

c++ - 什么时候是浮点运算 'invalid' ?