如何在 xeus-cling jupyter 内核中使用 boost?

How do I use boost with the xeus-cling jupyter kernel?

我 运行ning Pop!_OS(ubuntu 派生)和 apt 从默认存储库安装了 boost(libboost-all-dev)。我知道它已正确安装,因为我可以使用 GCC 编译和 运行 简单的 boost odeint 示例。

然而,当我尝试 运行 使用 zeus-cling 内核的 jupyter notebook 中的相同示例时,我在包含 odeint header 时遇到错误。我可以在执行此代码时重现错误:

#pragma cling add_include_path("/usr/include")
#include <boost/numeric/odeint.hpp>

我收到的错误信息是:

In file included from input_line_8:1:
In file included from /usr/include/boost/numeric/odeint.hpp:22:
In file included from /usr/include/boost/numeric/odeint/config.hpp:44:
In file included from /usr/include/boost/config.hpp:48:
In file included from /usr/include/boost/config/stdlib/libstdcpp3.hpp:78:
/usr/include/unistd.h:756:28: error: expected function body after function declarator
extern __pid_t fork (void) __THROWNL;
                           ^
/usr/include/unistd.h:869:11: fatal error: 'bits/getopt_posix.h' file not found
# include <bits/getopt_posix.h>
          ^~~~~~~~~~~~~~~~~~~~~
Interpreter Error: 

据我了解 bits/getopt_posix.h 只是一个 GCC header,因此我认为问题可能是因为 boost header 正在配置自己,就好像它们是在 GCC 下编译一样而不是 cling/clang。

那么,如何在 xeus-cling jupyter notebook 中正确包含 boost?

我很绝望,最终得到了以下解决我问题的方法。

所以我所做的是将 boost 超级项目作为子模块克隆到我的存储库中,然后添加使 boost::numeric::odeint 工作所需的所有包含路径。无论如何,Odeint 只是 header,所以它可以工作。这应该适用于所有 header only boost 库。

我猜这不是正确的方法,但对我有用。只是为了后面的原型设计和小实验。

这是谐波振荡器示例。

#pragma cling add_include_path("../lib/boost/libs/numeric/odeint/include")
#pragma cling add_include_path("../lib/boost/libs/numeric/ublas/include")
#pragma cling add_include_path("../lib/boost/libs/config/include")
#pragma cling add_include_path("../lib/boost/libs/type_traits/include")
#pragma cling add_include_path("../lib/boost/libs/serialization/include")
#pragma cling add_include_path("../lib/boost/libs/core/include")
#pragma cling add_include_path("../lib/boost/libs/preprocessor/include")
#pragma cling add_include_path("../lib/boost/libs/static_assert/include")
#pragma cling add_include_path("../lib/boost/libs/mpl/include")
#pragma cling add_include_path("../lib/boost/libs/utility/include")
#pragma cling add_include_path("../lib/boost/libs/typeof/include")
#pragma cling add_include_path("../lib/boost/libs/array/include")
#pragma cling add_include_path("../lib/boost/libs/assert/include")
#pragma cling add_include_path("../lib/boost/libs/throw_exception/include")
#pragma cling add_include_path("../lib/boost/libs/units/include")
#pragma cling add_include_path("../lib/boost/libs/integer/include")
#pragma cling add_include_path("../lib/boost/libs/fusion/include")
#pragma cling add_include_path("../lib/boost/libs/range/include")
#pragma cling add_include_path("../lib/boost/libs/iterator/include")
#pragma cling add_include_path("../lib/boost/libs/concept_check/include")
#pragma cling add_include_path("../lib/boost/libs/detail/include")
#pragma cling add_include_path("../lib/boost/libs/function_types/include")
#pragma cling add_include_path("../lib/boost/libs/predef/include")
#pragma cling add_include_path("../lib/boost/libs/math/include")
#pragma cling add_include_path("../lib/boost/libs/lexical_cast/include")
#pragma cling add_include_path("../lib/boost/libs/numeric/conversion/include")
#pragma cling add_include_path("../lib/boost/libs/container/include")
#pragma cling add_include_path("../lib/boost/libs/move/include")
#pragma cling add_include_path("../lib/boost/libs/smart_ptr/include")
#pragma cling add_include_path("../lib/boost/libs/multi_array/include")
#pragma cling add_include_path("../lib/boost/libs/functional/include")
#pragma cling add_include_path("../lib/boost/libs/function/include")
#pragma cling add_include_path("../lib/boost/libs/type_index/include")
#pragma cling add_include_path("../lib/boost/libs/container_hash/include")
#pragma cling add_include_path("../lib/boost/libs/bind/include")


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

typedef std::vector< double > state_type;
const double gam = 0.15;

void harmonic_oscillator(const state_type &x , state_type &dxdt , const double t)
{
    dxdt[0] = x[1];
    dxdt[1] = -x[0] - gam*x[1];
}

state_type x(2);
x[0] = 1.0; // start at x=1.0, p=0.0
x[1] = 0.0;

size_t steps = boost::numeric::odeint::integrate(harmonic_oscillator,
                                                 x , 0.0 , 10.0 , 0.1 );

std::cout << steps << std::endl;

Hi 在那里,

到目前为止,我一直在 xeus-cling 内核中使用 boost(几何),没有任何问题。我从 conda forge 安装 boost(conda install boost -c conda-forge)。 我试图在我的粘附环境中包含 odeint.hpp 而没有任何问题:

BTW 乔治斯