How to debug ctypes without error message
<p>I have a simple python script that uses a c/c++ library with <code>ctypes</code>. My c++ library also contains a main method, so I can compile it without the <code>-shared</code> flag and it can be excecuted and it runs without issues.</p>

<p>However, when I run the same code from a python script using <code>ctypes</code>, a part of the c++ program is excecuted (I can tell that from the <code>cout</code> calls). Then the entire  application, including the python script, termiantes (I can tell that from the missing <code>cout</code> and <code>print</code> calls). There is no error message, no segfault, no python stacktrace.</p>

<p>My question is: How can I debug this? What are possible reasons for this to happen?</p>

<p>Here is part of the code, however, since there is no error message, I don't know which code is relevant.</p>

<pre><code>import ctypes

interface = ctypes.CDLL("apprunner.so")
interface.start()
print "complete"
</code></pre>

<p>.</p>

<pre><code>#include "../../app/ShaderApp.cpp"
#include &lt;iostream&gt;
#include "TestApp.cpp"

TestApp* app = 0;

extern "C" void start() {
    app = new TestApp();
    cout &lt;&lt; "Running from library" &lt;&lt; endl;
    app-&gt;run();
}

int main( int argc, const char* argv[]) {
    cout &lt;&lt; "Running from excecutable" &lt;&lt; endl;
    start();
}
</code></pre>

<p>Typically you begin from a small mock-up library that just lets you test the function calls from python. When this is ready (all the debug prints are ok) you proceed further. In your example, comment out #include "testapp.cpp" and get the prints to cout working.</p>

python c++ ctypes