gpt4 book ai didi

c++ - 如何将 boost 与 xeus-cling jupyter 内核结合使用?

转载 作者:行者123 更新时间:2023-12-02 10:03:55 27 4
gpt4 key购买 nike

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

但是,当我尝试使用 zeus-cling 内核在 jupyter 笔记本中运行相同的示例时,在包含 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/铛。

那么,如何在 xeus-cling jupyter 笔记本中正确包含 boost 呢?

最佳答案

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

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

我的猜测是这不是正确的方法,但它对我有用。它仅用于稍后的原型(prototype)设计和小型实验。

这是谐波振荡器的示例。

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

关于c++ - 如何将 boost 与 xeus-cling jupyter 内核结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61205040/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com