title: How to solve the 'Segmentation fault' when hybrid programming of C & Python?
body: <p>Under my Ubuntu:</p>
  
  <p>$ cat test.py </p>
  
  <pre><code>#Filename test.py 
  def Hello(): 
      print "Hello, world!" 
  </code></pre>
  
  <p>$ cat tom.cpp </p>
  
  <pre><code>#include &lt;Python.h&gt; 
  
  int main() 
  { 
       Py_Initialize(); 
  
       PyObject * pModule = NULL; 
       PyObject * pFunc   = NULL; 
  
       pModule = PyImport_ImportModule("test");
       pFunc   = PyObject_GetAttrString(pModule, "Hello"); 
       PyEval_CallObject(pFunc, NULL); 
  
       Py_Finalize(); 
  
       return 0; 
  } 
  </code></pre>
  
  <p>And then compile it:</p>
  
  <pre><code>g++ tom.cpp -I/usr/include/python2.7 -L/usr/lib/python2.7 -lpython2.7
  </code></pre>
  
  <p>Run:
  $ ./a.out </p>
  
  <pre><code>Segmentation fault
  </code></pre>
  
  <p>Why?
  Could anyone help?
  Thanks!</p>
  
  <p>BR,
  Tom</p>