【问题标题】:boost::python import function fails with "Access violation reading location"boost::python 导入函数因“访问冲突读取位置”而失败
【发布时间】:2021-03-26 13:33:29
【问题描述】:

我正在尝试导入 python 脚本 testscript.py 并使用 boost::python 在 c++ 中运行 testfunction。但是 boost::python 在导入行失败。 scriptModule, scriptFunc 在别处声明boost::python::object

我应该提到,单独使用 PyImport_ImportModule("testscript") 有效。

    try {
        Py_Initialize();

        scriptModule = import("testscript");
        scriptFunc = scriptModule.attr("testfunction");
    }
    catch (...) {
        PyErr_Print();
    }

堆栈跟踪:

    python39.dll!_PyObject_GC_Alloc(int use_calloc, unsigned int basicsize) Line 2214   C
    [Inline Frame] python39.dll!_PyObject_GC_Malloc(unsigned int) Line 2252 C
    [Inline Frame] python39.dll!_PyObject_GC_New(_typeobject *) Line 2264   C
    python39.dll!new_dict(_dictkeysobject * keys, _object * * values) Line 628  C
    [Inline Frame] python39.dll!PyDict_New() Line 723   C
    python39.dll!PyUnicode_InternInPlace(_object * * p) Line 15601  C
    [Inline Frame] python39.dll!PyUnicode_InternFromString(const char *) Line 15645 C
    python39.dll!PyImport_Import(_object * module_name) Line 2028   C
    python39.dll!PyImport_ImportModule(const char * name) Line 1488 C
>   boost_python39-vc141-mt-gd-x32-1_75.dll!boost::python::import(boost::python::str name) Line 20  C++

【问题讨论】:

    标签: c++ boost boost-python


    【解决方案1】:

    这里的问题是我在调试时编译我的应用程序,而我编译的 boost 库没有链接到 python 的调试 dll,即 python39_d.dll,正如您在堆栈跟踪中看到的那样,dll 是发布一个python39.dll。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多