Extending Python 3 with C++
<p>I'm trying to extend Python 3 using instructions given <a href="http://docs.python.org/release/3.1.3/extending/extending.html" rel="nofollow">here</a> and I'm fairly confident I've followed the instructions correctly so far, but it asks me to include this code:</p>

<pre><code>PyMODINIT_FUNC
PyInit_spam(void)
{
    PyObject *m;

    m = PyModule_Create(&amp;spammodule);
    if (m == NULL)
        return NULL;

    SpamError = PyErr_NewException("spam.error", NULL, NULL);
    Py_INCREF(SpamError);
    PyModule_AddObject(m, "error", SpamError);
    return m;
}
</code></pre>

<p>I'm writing this in MSVC++ 2010 and it's warning me that &amp;spammodule is undefined (the name of the module is spammodule.cpp), but it doesn't define it anywhere in the instructions so I assume that it should recognise it automatically as the name of the module.</p>

<p>The full code is:</p>

<pre><code>#include &lt;Python.h&gt;
#include &lt;iostream&gt;
using namespace std;

static PyObject *SpamError;

int main()
{
    cout &lt;&lt; "Test" &lt;&lt; endl;
    system("PAUSE");
    return(0);
}

static PyObject *spam_system(PyObject *self, PyObject *args)
{
    const char *command;
    int sts;

    if (!PyArg_ParseTuple(args, "s", &amp;command))
        return NULL;
    sts = system(command);
    return PyLong_FromLong(sts);
}

PyMODINIT_FUNC
PyInit_spam(void)
{
    PyObject *m;

    m = PyModule_Create(&amp;spammodule);
    if (m == NULL)
        return NULL;

    SpamError = PyErr_NewException("spam.error", NULL, NULL);
    Py_INCREF(SpamError);
    PyModule_AddObject(m, "error", SpamError);
    return m;
}
</code></pre>
