PythonCE Wiki : SConsBuild

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
This article will help you to easily build PythonCE C extension with your desktop windows

Requirements



Setting up the build environment


Create a directory on your file system, it will contains the fies needed for compilation. In this article I will use C:\Pythonce\ .
From the source of pythonce 2.5 copy the following files & directories to C:\Pythonce\ :

Unpack the dev package and copy include/ and lib/ dirs to C:\Pythonce
Now you are ready to build your first extension.

Building an extension

Here is an example of a C extension :
spammodule.c
#include <stdlib.h>
#include "Python.h"

static PyObject *spam_spam(PyObject *self, PyObject *args)
{
	PyObject *py_spam, *out;
	const char *spam = "Spam, spam & spam !!! ";
	int i, n;

	if (!PyArg_ParseTuple(args, "i", &n))
	{
		return NULL;
	}
	py_spam = PyString_FromString(spam);
	out = PyString_FromString("");
	for (i=0; i<n; i++){
	    PyString_Concat(&out, py_spam);
	}
	return out;
}

static PyMethodDef SpamMethods[] = {{"spam", spam_spam, METH_VARARGS, "spam(n) -> produces n spam"}, 
	                                             {NULL, NULL, 0, NULL}};

PyMODINIT_FUNC
initspam(void)
{
	(void) Py_InitModule("spam", SpamMethods);
}


Create the following build script under the name "SConscript" :
class CEBuildEnvironment(Environment):
	def __init__(self):
	    Environment.__init__(self, 	 
	        MSEVC_PLATFORM = 'POCKET PC 2003',
	        MSEVC_SUBPLATFORM = 'Win32 (WCE ARMV4)',
	        tools = ['mslink', 'msevc', 'zip'],
	        toolpath = '.'
	        )

class PythonCEBuildEnvironment(CEBuildEnvironment):
	def __init__(self):
	    CEBuildEnvironment.__init__(self)
	    self.Append(CPPDEFINES = ['WIN32'],
	                LIBS=["python25"],
	                CPPPATH=["include"],
	                LIBPATH=["lib"])

	def PythonExtension(self, target, sources, **kw):
	    self.SharedLibrary(target, sources, SHLIBSUFFIX='.pyd', **kw)

env = PythonCEBuildEnvironment()
env.PythonExtension("build/spam.pyd", "spammodule.c")


To build the extension, launch a command console (Start->run->cmd.exe), cd to C:\pythonce and type scons on the command line.

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0339 seconds