Seite 1 von 1

Probleme beim erstellen einer C Extension

Verfasst: Montag 25. Februar 2008, 19:37
von Samhayne
Hallo,

Ich kämpfe nun schon seit Tagen mit dem Erstellen einer C Extension herum... doch irgendwie will es nicht gelingen.
Ich hoffe, Ihr könnt mir weiterhelfen.

Hier der C Code (abgepinselt aus der Python Bible)

Code: Alles auswählen

#include <Python.h>

//add two arbitrary Objects
static PyObject *simple_add(PyObject *pSelf, PyObject *pArgs)
{
	PyObject *pX, *pY;

	if (!PyArg_ParseTuple(pArgs, "OO", &pX, &pY))
		return NULL;

	return PyNumber_Add(pX,pY);
}

// a doc string
static char count_doc[] = "Returns the number of arguments passed in";

static PyObject *simple_count(PyObject *pSelf, PyObject *pArgs)
{
	long count = PyTuple_Size(pArgs);
	return PyInt_FromLong(count);
}

// Map of function names to functions
static PyMethodDef simple_methods[] = 
{
	{"add", simple_add, METH_VARARGS, NULL},
	{"count", simple_count, METH_VARARGS, count_doc	},
	{NULL, NULL} //End of functions

};

extern "C" DL_EXPORT(void) initsimple()
{
	Py_InitModule("simple", simple_methods);
}
(ich hoff', das mit dem extern "C" passt so.)


Okay... das ganze also in ein VC8 Projekt gepackt... und so konfiguriert, daß er mir eine lib oder dll baut.
------ Erstellen gestartet: Projekt: simple, Konfiguration: Release Win32 ------
Kompilieren...
imageProc.cpp
Verknüpfen...
Code wird generiert.
Codegenerierung ist abgeschlossen.
Das Buildprotokoll wurde unter "file://c:\Python Projects\RueLaSchraat\dependencies\C_Extensions\VC8 Workspace\C_Extensions\C_Extensions\Release\BuildLog.htm" gespeichert.
simple - 0 Fehler, 0 Warnung(en)
========== Erstellen: 1 erfolgreich, Fehler bei 0, 0 aktuell, 0 übersprungen ==========
Doch beides (sowohl dll und lib) funktioniert nicht:
C:\Python Projects\RueLaSchraat\dependencies\C_Extensions\lib>dir
Datenträger in Laufwerk C: ist SaberRider
Volumeseriennummer: 3C8F-0C0C

Verzeichnis von C:\Python Projects\RueLaSchraat\dependencies\C_Extensions\lib

25.02.2008 19:21 <DIR> .
25.02.2008 19:21 <DIR> ..
25.02.2008 19:21 6.144 simple.dll
25.02.2008 19:21 4.702 simple.lib
2 Datei(en) 10.846 Bytes
2 Verzeichnis(se), 2.097.717.248 Bytes frei

C:\Python Projects\RueLaSchraat\dependencies\C_Extensions\lib>..\..\Python251\python.exe
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import simple
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named simple
>>>
Er findet das Modul einfach nicht, obwohl ich Python aus dem Modulpfad heraus starte.




Hier noch der Vollständigkeit halber das VC8 Projekt:

http://wwwstud.ira.uka.de/~s_walser/C_Extensions.rar