# extending python

This topic is 3257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i want to write some extension modules, but every time i try something it fails. i know one usually extends with C, but i'm using C++. the code i'm trying is:
#include <Python.h>
int a, b, sum;
static PyObject *
{
if (!PyArg_ParseTuple(args, "ii", &a, &b))
return NULL;
sum = a + b;
return Py_BuildValue("i", sum);
}

{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
{
}

but it says: one unresolved external. can somebody please help me? one note: i don't want to use any library (boost, ect.) assainator

##### Share on other sites
I have no idea what's wrong with what you are doing. What I normally do, is just take a working example extension module, replace the example code with my own and rename it. Then go from there.

Developing primarily on Windows, I use this as a base, and this documentation section as a refresher.

##### Share on other sites
thanks, but for some reason it can't compile, downloaded all the files, use "python setup.py build" but says this:
Quote:
 c:\python26\include\pyconfig.h(233) : fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory

assainator

##### Share on other sites
Quote:
Original post by assainator
thanks, but for some reason it can't compile, downloaded all the files, use "python setup.py build" but says this:
Quote:
 c:\python26\include\pyconfig.h(233) : fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory

assainator

In order for others to have enough detail to help you, you need to provide a reasonable level of detail. In your first post, you did not mention what the unresolved symbol was, what platform you were using or what compiler (and version of it) you were using.

Without that information, they need to guess the missing information to provide help that may or may not be relevant. I don't know about other people, but I don't have the time to spend speculating solutions to problems which do not have the context to be fully understood.

However, I will say that when I am compiling something and I get an error I have not seen before, the first thing I do is google it. Nine times out of ten, I can find someone else with the same problem and replies describing what is missing. For instance, in the link given for the first match I see has this solution. Here's another solution also in the first page of links, which is in an FAQ into which it looks a lot of effort has gone into.

##### Share on other sites
sorry, at the time i tought it was enough informations.
i'll try to give more explanation next time.

But i if i try to compile this:
#include "Python.h"static PyObject *ex_foo(PyObject *self, PyObject *args){	printf("Hello, world\n");	Py_INCREF(Py_None);	return Py_None;}static PyMethodDef example_methods[] = {	{"foo", ex_foo, METH_VARARGS, "foo() doc string"},	{NULL, NULL}};PyMODINIT_FUNCinitexample(void){	Py_InitModule("example", example_methods);}

i get this output from my setup.py:
Quote:
 running installrunning buildrunning build_extbuilding 'example' extensionC:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python26\include -IC:\Python26\PC /Tpexample3.cpp /Fobuildtemp.win32-2.6\Release\example3.objexample3.cppC:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild /EXPORT:initexample build\temp.win32-2.6\Release\example3.obj /OUT:build\lib.win32-2.6\example.pyd /IMPLIB:build\temp.win32-2.6\Release\example.lib /MANIFESTFILE:build\temp.win32-2.6\Release\example.pyd.manifestLINK : error LNK2001: unresolved external symbol initexamplebuild\temp.win32-2.6\Release\example.lib : fatal error LNK1120: 1 unresolved externalserror: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"'failed with exit status 1120

how do i fix this?

assainator

##### Share on other sites
Quote:
 Original post by assainatorLINK : error LNK2001: unresolved external symbol initexamplebuild\temp.win32-2.6\Release\example.lib : fatal error LNK1120: 1 unresolved externalserror: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"'failed with exit status 1120how do i fix this? assainator

Seems like there are some good matches there which show people commenting on the same error.

##### Share on other sites
yes and i've searched 5 pages before posting here and NO solution........

assainator

##### Share on other sites
Quote:
 Original post by assainatoryes and i've searched 5 pages before posting here and NO solution........assainator

This is confusing me. Are you reading the linked pages in the results of the linked search I gave? The one I picked to look at first had someone saying something like "I had an error 'unresolved external symbol'" and then proceeding to say something like "I did this and it then compiled." Is that what you consider to be a possible solution? I consider it to be one.

This was a simple matter of googling with the exact error message, choosing a result and finding the part of the page which quoted that exact error message.

• 17
• 11
• 12
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999758
×