[Tutor] First extension

James Reynolds eire1130 at gmail.com
Sat Mar 27 03:03:06 CET 2010


Hello All,

I'm trying to write my first extension module, and I am getting the
following error in my command prompt and I was hoping you all could help me.

I have taken the following steps already:


   1. My path is set for mingw/bin as well as python31.
   2. There is a file in my disutils folder called disutils.cfg that says
   [build] compiler = mingw32
   3. The instructions in the 3.1 documentation state the following: "These
   instructions only apply if you’re using a version of Python prior to 2.4.1
   with a MinGW prior to 3.0.0 (with binutils-2.13.90-20030111-
      1. http://docs.python.org/py3k/install/index.html
      2. I am using Python 3.1 and the latest MinGW.
   4. I tested gcc/mingw by doing C:\python31>gcc -shared pdv.c -o pdv.dll
   and the test was succesful (or at least I was not given any errors while
   doing the compile)
   5. I searched on the internet and the closest thing I can find is the
   following: http://bugs.python.org/issue4709


Below you will find the following

One, the error report
two,my setup.py file
three, the file I am trying to turn into a python extension module by
running the following two commands:

python setup.py build
python setup.py install


#1


Microsoft Windows [Version 6.1.7600]

Copyright (c) 2009 Microsoft Corporation.  All rights reserved.


> c:\Python31\Lib\finance>python setup.py build

running build

running build_ext

building 'finance' extension

creating build

creating build\temp.win-amd64-3.1

creating build\temp.win-amd64-3.1\Release

C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python31\include
> -IC:\Pytho

n31\PC -c finance.c -o build\temp.win-amd64-3.1\Release\finance.o

finance.c: In function `PyInit_finance':

finance.c:31: warning: implicit declaration of function `Py_Module_Create'

finance.c:31: warning: return makes pointer from integer without a cast

writing build\temp.win-amd64-3.1\Release\finance.def

creating build\lib.win-amd64-3.1

C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s
> build\temp.win-amd64-3.1\Release\fin

ance.o build\temp.win-amd64-3.1\Release\finance.def -LC:\Python31\libs
> -LC:\Pyth

on31\PCbuild\amd64 -lpython31 -lmsvcr90 -o
> build\lib.win-amd64-3.1\finance.pyd

build\temp.win-amd64-3.1\Release\finance.o:finance.c:(.text+0x2b): undefined
> ref

erence to `_imp__PyArg_ParseTuple'

build\temp.win-amd64-3.1\Release\finance.o:finance.c:(.text+0x5c): undefined
> ref

erence to `_imp__Py_BuildValue'

build\temp.win-amd64-3.1\Release\finance.o:finance.c:(.text+0x74): undefined
> ref

erence to `Py_Module_Create'

collect2: ld returned 1 exit status

error: command 'gcc' failed with exit status 1


> c:\Python31\Lib\finance>



#2


from distutils.core import setup, Extension


> setup(name = "finance",

      version = "1.0",

      ext_modules = [Extension("finance", ["finance.c"])])



#3

#include <Python.h>

#include <math.h>


> static PyObject *

pdv(PyObject *self, PyObject *args)

{

double value, rate, timex, denom, pdvx;

if (!PyArg_ParseTuple(args, "ddd", &value, &rate, &timex))

return NULL;

    denom = (double) pow ((1 + rate), (timex));

    pdvx = value / denom;

return Py_BuildValue("d", pdvx);

}

PyMethodDef pdvMethods[] = {

    {"pdv", pdv, METH_VARARGS, "Returns the Present Discounted Value given
> of a single future value"},

    {NULL, NULL, 0, NULL}

};


> static struct PyModuleDef financemodule = {

   PyModuleDef_HEAD_INIT,

   "finance",   /* name of module */

   NULL, /* module documentation, may be NULL */

   -1,       /* size of per-interpreter state of the module,

                or -1 if the module keeps state in global variables. */

   pdvMethods

};


> PyMODINIT_FUNC

PyInit_finance(void)

{

    return Py_Module_Create(&financemodule);

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100326/5e8a8f20/attachment-0001.html>


More information about the Tutor mailing list