## 5.11 How do I interface to C++ objects from Python? 

Depending on your requirements, there are many approaches. To do this manually, begin by reading the “Extending and Embedding” document. Realize that for the Python run-time system, there isn’t a whole lot of difference between C and C++ – so the strategy of building a new Python type around a C structure (pointer) type will also work for C++ objects. 

For C++ libraries, see Writing C is hard; are there any alternatives? . 

## 5.12 I added a module using the Setup file and the make fails; why? 

Setup must end in a newline, if there is no newline there, the build process fails. (Fixing this requires some ugly shell script hackery, and this bug is so minor that it doesn’t seem worth the effort.) 

## 5.13 How do I debug an extension? 

When using GDB with dynamically loaded extensions, you can’t set a breakpoint in your extension until your extension is loaded. 

In your$_{.gdbinit}$file (or interactively), add the command: 

br _PyImport_LoadDynamicModule 

Then, when you run GDB: 

$ gdb /local/bin/python gdb) run myscript.py gdb) continue # repeat until your extension is loaded gdb) finish # so that your extension is loaded gdb) br myfunction.c:50 gdb) continue 

## 5.14 I want to compile a Python module on my Linux system, but some files are missing. Why? 

Most packaged versions of Python don’t include the$_{/usr/lib/python2.}$ x /config/ directory, which con- tains various files required for compiling Python extensions. 

For Red Hat, install the python-devel RPM to get the necessary files. 

For Debian, run$_{apt-get install python-dev}$ . 

## 5.15 How do I tell “incomplete input” from “invalid input”? 

Sometimes you want to emulate the Python interactive interpreter’s behavior, where it gives you a continuation prompt when the input is incomplete (e.g. you typed the start of an “if” statement or you didn’t close your parentheses or triple string quotes), but it gives you a syntax error message immediately when the input is invalid. 

In Python you can use the$_{codeop}$ module, which approximates the parser’s behavior sufficiently. IDLE uses this, for example. 

The easiest way to do it in C is to call PyRun_InteractiveLoop() (perhaps in a separate thread) and let the Python interpreter handle the input for you. You can also set the$_{PyOS_ReadlineFunctionPointer()}$ 

