如何创建空的工作boost::python::dict

How to create empty working boost::python::dict?

本文关键字:boost 工作 python dict 何创建 创建      更新时间:2023-10-16

我解析了一个C++项目,该项目编译为python的library.so。所以我无法在Qt创建者IDE中调试它。为此,我使用可执行文件main()创建了单独的项目:

int main()
{
    boost::python::dict whiteList;
    whiteList.has_key("blablabla");
    ...
    return 0;
}

在发布模式下,程序编译和工作不正确。但在调试模式下程序在has_key()方法中失败,并出现错误窗口:

The inferior stopped because it received a signal from the Operating System.
Signal name :    SIGSEGV
Signal meaning : Segmentation fault

问题可能是:如何在不涉及python脚本的情况下,在C++程序中正确创建和使用boost::python::dict

无论何时使用Python C API或Boost Python,都必须初始化Python:

Py_Initialize();

将其添加到您的main() et voila的顶部。