my cpp file is this:
#include <pybind11/pybind11.h>
#include <iostream>
namespace py = pybind11;
int main() {
auto math = pybind11::module::import("math");
auto resultobj = math.attr("sqrt")(2);
double result = resultobj.cast<double>();
std::cout << "The square root of 2 is: " << result << "\n";
}
when I try to compile it using this command:
g++ -Wall -std=c++11 -fPIC -I/home/qwert/miniconda3/include -I/home/qwert/miniconda3/include/python3.9 fn_call.cpp
I get a lot of errors which I have not been able to fix
first few lines of errors:
/usr/bin/ld: /tmp/cc61RVdo.o: in function `_Py_DECREF':
fn_call.cpp:(.text+0x74): undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/cc61RVdo.o: in function `pybind11::type_error::set_error() const':
fn_call.cpp:(.text._ZNK8pybind1110type_error9set_errorEv[_ZNK8pybind1110type_error9set_errorEv]+0x2d): undefined reference to `PyExc_TypeError'
/usr/bin/ld: fn_call.cpp:(.text._ZNK8pybind1110type_error9set_errorEv[_ZNK8pybind1110type_error9set_errorEv]+0x3b): undefined reference to `PyErr_SetString'
/usr/bin/ld: /tmp/cc61RVdo.o: in function `pybind11::cast_error::set_error() const':
fn_call.cpp:(.text._ZNK8pybind1110cast_error9set_errorEv[_ZNK8pybind1110cast_error9set_errorEv]+0x2d): undefined reference to `PyExc_RuntimeError'
/usr/bin/ld: fn_call.cpp:(.text._ZNK8pybind1110cast_error9set_errorEv[_ZNK8pybind1110cast_error9set_errorEv]+0x3b): undefined reference to `PyErr_SetString'
I have tried reinstalling python, pybind11, and even trying it on a different linux machine