1
votes

I am really inexperienced in programming. I am having troubles installing odeint (and boost) to solve a system of differential equations. I have been looking at a lot of questions about installing boost tried a lot of them, but I have not been able to use odeint yet. I am using Mac Yosemite 10.10.5 Below are my questions, I really appreciate your help livesavers:

1, If I can install boost sucessfully, then when I want to use odeint, do I just need to include #include<boost/odeint/optionalSubdirectories> as the header of my file? I got confused because on the odeint webpage, there are files for downloads, which include examples. I was wondering if I have to download these files in order to make odeint work after I have downloaded boost? If yes, where should I put the downloaded files from odeint webpage?

2, In the boost's installing instructions, they said the second step (after downloading) is to execute tar --bzip2 -xf /path/to/boost_1_61_0.tar.bz2 in the directory where I want to put the Boost installation. Where is a good place to put my Boost installation? After I do this, can I just start including header files into my c++ projects? Or do I have to do something else before odeint actually works?

3, When I compile my files (after writing codes to solve differential equations), do I have to do anything with boost or odeint, or do I just compile my files as usual?

I am sorry if my questions sound dumb. As I mentioned, I am inexperienced. I really hope for your help!

2
Try this: Install Homebrew, then brew install boost - Nick Matteo

2 Answers

1
votes

The library odeint is just header files. Download it and include the path to the header files. Assuming you've installed boost library. That's all.

0
votes

I directly use the sources from the boost github repository to install boost for my project. Doing so I can be sure that all developers using the same sources and the sources as well as the libs and headers are directly available for them (no need for installation into the OS).

Therefore I create a small bash script which downloads, build and install boost:
./cmake/SetupBoost.sh

#!/bin/bash

NO_OF_CORES_TO_USE=$(($(nproc --all)-1))

echo "   > collect boost setup information"
if [ $# -eq 1 ]
then
    echo "arguments supplied"
    BOOST_ROOT_DIR=$1
    BOOST_VERSION="latest"
elif [ $# -eq 2 ]
then
    BOOST_ROOT_DIR=$1
    BOOST_VERSION=$2
else
    echo "warning"
    exit -1
fi

BOOST_SOURCE_DIR="${BOOST_ROOT_DIR}/source"

if [ -d "${BOOST_SOURCE_DIR}/.git" ]; then
    echo "   > repository already exist - checkout"
    cd ${BOOST_SOURCE_DIR} && \
        git checkout tags/${BOOST_VERSION}
else
    echo "   > repository do not exist - clone"
    git clone \
        --branch ${BOOST_VERSION} \
        --recurse-submodules \
        -j${NO_OF_CORES_TO_USE} \
        https://github.com/boostorg/boost.git \
        ${BOOST_SOURCE_DIR}
fi

echo "   > perform bootstrap"
cd ${BOOST_SOURCE_DIR} && ./bootstrap.sh

echo "   > build and install boost libraries"
cd ${BOOST_SOURCE_DIR} && ./b2 \
    link=static \
    runtime-link=static \
    install \
    --prefix=${BOOST_ROOT_DIR} \
    -j${NO_OF_CORES_TO_USE}

Where the script can be called like this:

./SetupBoost.sh <installDir> [version-tag]

Now I can invoke this script as CMake-target into CMake (I like to put the boost sources, headers and libs into ./extern/boost/):
./cmake/SetupBoost.cmake

cmake_minimum_required(VERSION 3.14)

set(BOOST_VERSION "boost-1.70.0")

set(BOOST_ROOT_DIR    ${EXTERN_ROOT_DIR}/boost)
set(BOOST_SOURCE_DIR  ${BOOST_ROOT_DIR}/source)
set(BOOST_LIBRARY_DIR ${BOOST_ROOT_DIR}/lib)
set(BOOST_INCLUDE_DIR ${BOOST_ROOT_DIR}/include)

### build boost sources ########################################################

add_custom_command(
    OUTPUT
        ${BOOST_INCLUDE_DIR}
        ${BOOST_ROOT_DIR}
    COMMAND
        bash ${PROJECT_SOURCE_DIR}/cmake/SetupBoost.sh ${BOOST_ROOT_DIR} ${BOOST_VERSION}
    WORKING_DIRECTORY
        ${PROJECT_SOURCE_DIR}
)

add_custom_target(
    boost_library
    DEPENDS
        ${BOOST_INCLUDE_DIR}
        ${BOOST_ROOT_DIR}
)

now I add this two lines to the main ./CMakeLists.txt:

set(EXTERN_ROOT_DIR ${PROJECT_SOURCE_DIR}/extern)
include(cmake/SetupBoost.cmake)

The corresponding ./app/CMakeLists.txt of my application now looks like this:

add_executable( ${PROJECT_NAME}
    app.cpp
)

add_dependencies( ${PROJECT_NAME}
    boost_library
)

target_include_directories( ${PROJECT_NAME} PRIVATE
    ${BOOST_INCLUDE_DIR}
)

the corresponding source file app/app.cpp can use the header like this:

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/math/special_functions/gamma.hpp>

// your code goes here