Skip to content
Advertisement

How to debug crashing C++ library loaded in python project

I am attempting to figure out why calling a function in a dynamically loaded lib crashes python. I’m doing the following, I have a C++ function in a dynamic library file, which is loaded in python using ctypes. I then call the function from python:

JavaScript

On MacOS, this works exactly as expected. Unfortunately on Windows 11, it does not. I’m running from a Jupyter notebook and the kernel crashes and restarts immediately after the lib.GetSection call.

I have attached the Visual Studio debugger to the process, and can see that on the C++ side of things, the function is being correctly called, all parameters are correct, and it returns without error. It is at this point that the python kernel crashes, deep in a python call stack that I don’t have symbols for.

How do I even approach debugging this? Does anything look wrong with the way I am calling the function?

Advertisement

Answer

Having a toy C++ function to demonstrate your problem would help. Below is a best guess C++ function with the same signature and the Python code to call it:

test.cpp

JavaScript

test.py

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement