Andres Huster
Andres Huster

Reputation: 31

PyBind11: simple invoke task, standard C++ library not found

i am trying to wrap the C++ library PyrochloreAFM.hpp which itself uses the lib boost/randoom.hpp so that i can import it as a python module. The C++ part itself works fine and i can succesfully import and use all of this from my main.

#include "PyrochloreAFM.hpp"
    
int main (int argc, const char *argv[]) {
     PyrochloreAFM pyrochloreAFM (&parameters, &statistics, &rng);
}

Now following a tutorial i set up my c++ wrapper:

// pybind11_wrapper.cpp
#include <pybind11/pybind11.h>
#include <PyrochloreAFM.hpp>

PYBIND11_MODULE(pybind11_example, m) {
    m.doc() = "pybind11 example plugin"; // Optional module docstring
    m.def("cpp_function", &PyrochloreAFM, "A function that multiplies two numbers");
}

and my tasks.py file

# tasks.py
import invoke

invoke.run(
    "g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC PyrochloreAFM.cpp "
    "-o libpyro.so "
)

However now $invoke build-PyrochloreAFM or even $invoke --list seem to have lost the track of the standard C++ library.

In file included from PyrochloreAFM.cpp:1:
./Parameters.hpp:16:10: fatal error: 'boost/random.hpp' file not found
#include "boost/random.hpp" // tested with boost 1.53
         ^~~~~~~~~~~~~~~~~~
1 error generated.

This might be a simple PATH problem so i would be very glad for any tips!

Thank you, Andres!

Upvotes: 0

Views: 225

Answers (1)

Andres Huster
Andres Huster

Reputation: 31

"Of course" the tasks.py file which compiles the .cpp file through the python module invoke has to instruct the compiler g++ to use the libraries we desire. In my case it is the flag -I /opt/homebrew/Cellar/boost/1.80.0/include i also use in my makefile or directly in terminal.

Upvotes: 2

Related Questions