1

I'm running Pop!_OS (ubuntu derivative) and apt installed boost (libboost-all-dev) from the default repositories. I know it has installed properly since I can compile and run the simple boost odeint example with GCC.

However when I tried to run the same example inside a jupyter notebook using the zeus-cling kernel I got an error while including the odeint header. I can recreate the error while executing this code:

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

The error message I get is:

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: 

From what I understand bits/getopt_posix.h is a GCC only header, thus I think the problem might be because the boost headers are configuring themselves as if they are compiling under GCC instead of cling/clang.

So, how do I properly include boost in a xeus-cling jupyter notebook?

Aaron de Windt
  • 16,794
  • 13
  • 47
  • 62
  • Adding the compiled shared libraries (*.so) is not necessary in this case since `odeint` is header only. I did try it nonetheless. – Aaron de Windt Apr 14 '20 at 09:59

2 Answers2

3

I was getting desperate which ended up in the following solution to my problem.

So what I did is clone the boost super project as a submodule into my repository and then added all include paths required to get boost::numeric::odeint working. Odeint is header only anyways, so it works. This should work for all header only boost libraries.

My guess is that this is not the proper way, but it works for me. It's just for prototyping and small experiments later on.

Here is the harmonic oscilator example.

#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;
Aaron de Windt
  • 16,794
  • 13
  • 47
  • 62
1

Ηi there,

I ve been using boost (geometry) with xeus-cling kernel without any issues, so far. I install boost from conda forge (conda install boost -c conda-forge). I tried to include odeint.hpp without any issues on my cling environment:

enter image description here

ΒW Giorgos

GioR
  • 596
  • 2
  • 8
  • 19
  • Thanks, I'll try it out next time I continue working on this project. This weekend. It makes sense though. Installing it through conda instead of using the system install. – Aaron de Windt Jun 17 '20 at 00:45