Search code examples
c++qtboostinitializationboost-python

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


I parse a C++ project which compiling as library.so for python. So I can`t debug it inside Qt creator IDE. For this purpose I created separate project with executable main():

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

On release mode program compiling and work incorrectly. But on debugging mode program fails in has_key() method with error window:

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

Probably the question is: How to correctly create and use boost::python::dict purely inside C++ program without involving python script?


Solution

  • Whenever you use the Python C API or Boost Python, you must initialize Python:

    Py_Initialize();
    

    Add that to the top of your main() et voila.