C++ 不能编译C++;它使用boost中的odeint

C++ 不能编译C++;它使用boost中的odeint,c++,ubuntu,boost,odeint,C++,Ubuntu,Boost,Odeint,我在Ubuntu 12.04上&在/usr/include中已经有了一些提升。我做了一个测试 sudo apt-get install libboost-all-dev 这也安装了很多文件。我不想从源代码中删除这个boost并进行安装,因为其他几个软件包都依赖于ubuntu repos的版本。这是我要运行的示例代码:- #include <iostream> #include <boost/numeric/odeint.hpp> using namespace s

我在Ubuntu 12.04上&在/usr/include中已经有了一些提升。我做了一个测试

sudo apt-get install libboost-all-dev
这也安装了很多文件。我不想从源代码中删除这个boost并进行安装,因为其他几个软件包都依赖于ubuntu repos的版本。这是我要运行的示例代码:-

#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;
    }
}
这一次,它没有说权限被拒绝,但抛出了400行错误,如图所示->


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

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


函数“int main()”中的后续错误
test.cpp:test.cpp:30:5:error:“stepper_euler”未在此范围内声明
指向另一个错误源:您忘记包含声明了
stepper_euler
的文件。将适当的
#include
放在代码开头。

首先:文件存在吗?是,所有必需的文件都存在可能是因为odeint与ubuntu repos提供的boost版本不兼容,并且除了从默认情况下提供odeint的源代码安装最新的boost之外别无选择?然后从日志中列出的第一个错误开始:
/usr/include/boost/numeric/odeint/stepper/controlled\u runge\u kutta.hpp:307:42:错误:“bind”不是“boost::numeric::odeint::detail”的成员。
。确保它实际上是第一个。您可以使用
-Wfatal errors
进行编译,以在出现第一个错误时中止。@stefan在/usr/include/boost/numeric/odeint/stepper/base/explicit\u stepper\u base.hpp:25:0,from/usr/include/boost/numeric/odeint/stepper/euler.hpp:23中包含-Wfatal errors标志,来自/usr/include/boost/numeric/odeint.hpp:27,来自test.cpp:2:/usr/include/boost/numeric/odeint/util/bind.hpp:44:14:错误:“std::bind”未声明编译终止,原因是-Wfatal errors'@headmyshoulder编译器错误注释中提供的OP建议不同。它似乎使用了
std::bind
,即C++11。我确信它在没有C++11的情况下也能工作(我是作者之一)。有预处理器宏检查是否启用了C++11。如果是,则使用std::bind,其他boost::bind。@headmyshoulder可能是用户的错误,使用了
std::bind
(由于缺少
-std=c++0x
),但从OP显示的情况来看,这似乎不太可能。我怀疑决定
boost::bind
.headmyshoulder和/stefan的逻辑中有一个bug,两者都是正确的。odeint与ubuntu repos上的boost版本[1.42]不兼容。我从sourceforge得到了最新的支持&构建了整个东西。然后按照stefan的建议进行编译。发布的示例是@headmyhoulder正确指出的旧版odeint版本。
g++-o示例-std=c++0x-Wfatal errors-example.cpp
让NVIDIA的CUDA编译器运行起来有点棘手,
nvcc-o示例-Xcompiler“-std=c++0x”示例.cpp
C++11启用是必要的,AFAIK仅在CUDA toolkit 5.5中可用。谢谢大家的帮助:)
sudo chmod -R +x odeint/