With the recommendation of pybind11, I am trying to call python libs in my C++ program these days(Ultimate goal: use pickle to read data in python, and pass them to C++). I used Visual Studio 2019 and python3.7(Anaconda Version) to do this job. Following the tutorial in pybind11 Doc, I practiced the simplest demo like that:
#pragma comment(lib, "python37.lib")
#pragma comment(lib, "python3.lib")
#include <iostream>
#include <pybind11/pybind11.h>
using namespace std;
namespace py = pybind11;
int main()
{
py::object Decimal = py::module::import("decimal").attr("Decimal");
}
But the VS2019 told me this:
Unhandled exception at 0x00007FFA9A5384E7 (python37.dll) in hello_Call_py_From_C.exe: 0xC0000005: Access violation reading location 0x0000000000000025.
The include and lib directories I used are :
Anaconda3\include, pybind11\include;
Anaconda3\libs;
When I continued to debug, it told me "unicodeobject.c not found", like this:
To make it clear, I searched the derecotories in my PC, and all the 'unicodeobject' is '.h' rather than '.c', which are mostly in the Anaconda Folder rather than pybind11:
I continued to check if decimal is not a illegal pac in python, but in fact it is:
So I am more puzzled and don't know who to be blamed. What't more, I would also appreciate if you can guide me to another wiser way to tackle this task. Thank you!
User contributions licensed under CC BY-SA 3.0