Help creating extension for C function

Java and Swing codecraig at
Tue Oct 11 20:42:03 CEST 2005

  I now have this.

#include <string.h>
#include <stdlib.h>
#include "Python.h"

int doStuff(const char *input, const char *d) { ... }

static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
	// get the arguments from Python
	int result;
	char *input = 0;
	char *d = 0;
	int ok = PyArg_ParseTuple(args, "ss", &input, &d);
	if (!ok) return 0;

	// make the function call
	result = doStfuff(input, d);

	// return the result
	return PyBuildValue("i", result);

static PyMethodDef functions[] =
	{"PyDoStuff", wrap_doStuff, METH_VARARGS, "some documentation"},

extern PyMODINIT_FUNC initDLLTester(void)
        "DLLTester", functions, "my doStfuff function", NULL,


...when I try to compile in Visual C++ 6, I get

   Creating library Release/DLLTester.lib and object
test.obj : error LNK2001: unresolved external symbol _PyBuildValue
Release/DLLTester.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Any ideas what's happening here?

DLLTester.dll - 2 error(s), 0 warning(s)

Fredrik Lundh wrote:
> Java and Swing wrote:
> > So is "module.c" a new C file or do I add it to my existing, myapp.c?
> it's a complete module.  if you want it to do something other than printing
> the arguments, replace the "do stuff" section with your own code.  if you
> want to call it something else, rename it.  if you want to change the API,
> change it.  it's not that large; you should be able to figure out what it does
> and how it does it in no time at all.
> </F>

More information about the Python-list mailing list