I have the following shared object: MyLib.cpp That I compile with: g++ -fPIC -shared -o MyLib.so MyLib.cpp I then use it with the following Python script: script.py Like this, it works perfectly, but if I uncomment the line //var = 10;, Python makes a segmentation fault (Python 3.8). This happens every time the object MyClass makes a change to one