0

I want to use functions from Boost C++ Libraries (like gauss_kronrod.hpp) in my Pybind11 project to optimize python using C++.

Using C++ functions from standard libraries (like numeric) is straightforward:

#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <numeric>
namespace py = pybind11;
.
.
.
PYBIND11_MODULE(_test, m) {
    m.def("test_func", &test_func);
}

How can I access all the functions from Boost? I downloaded it and saved it in the folder thirdparty of my Pybind11 project. I can include a single function from Boost using to complete path to this function:

# include <thirdparty/boost/boost/math/quadrature/gauss_kronrod.hpp>

However func.hpp loads other functions from Boost which can not be found. I feel like I need to add the Path to Boost in my file CMakeLists.txt.

Under PyBind11: boost::multiprecision::cpp_int to Python is an example where cpp_int.hpp from Boost was successfully used within Pybind11. Unfortunately, its not clear how they made the command

#include <boost/multiprecision/cpp_int.hpp>

work properly

evva
  • 11
  • 2
  • If when you downloaded it, you downloaded the repo including its CMakeLists.txt file, I believe in your cmake config, you can do something like `add_subdirectory(thirdparty/boost)`, and then do your usual `target_link_libraries(your_library Boost::boost)` – starball Jul 20 '22 at 02:52
  • Apparently there is no CMakeLists.txt. But your comment made me realize how search for an answer to my question. Found it here: https://stackoverflow.com/questions/3897839/how-to-link-c-program-with-boost-using-cmake – evva Jul 20 '22 at 08:27
  • please note that the answer in that thread that most aligns with modern best-practice at this time is this one: https://stackoverflow.com/a/43885372/11107541. the higher voted answers are older / out of date. I do wonder if they will work for you, since you seem to have done some interesting thirdparty thing. You may be interested in using a package/dependency manager like vcpkg or conan (or maybe CPM). – starball Jul 20 '22 at 08:53

0 Answers0