
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 successful (or at least I was not given any errors while doing the compile). The pdv is a simple math formula. I am able to use the 64 bit version of this dll in ctypes, but not the 32 version. 5. I searched on the internet and the closest thing I can find is the following: http://bugs.python.org/issue4709 6. I suspected I might be having an issue with 64 bit compatibility, but I can't get the mingw64 bit compiler to run: "error: don't know how to compile C/C++ code on platform 'nt' with 'x86_64-w64-mingw32-gcc' compiler.
I am running Windows 7 64 bit version, I have installed the Python 3.1.2 64 bit interpreter. I have the MinGW32 and the one referenced above as well.
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);
}

On Sat, Mar 27, 2010 at 10:34 PM, James Reynolds eire1130@gmail.com wrote:
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:
Are you trying to build a C extension or something importable by ctypes ?
I am running Windows 7 64 bit version, I have installed the Python 3.1.2 64 bit interpreter. I have the MinGW32 and the one referenced above as well.
Mingw is useless, since you want to build a 64 bits extension. You have to use mingw-w64.
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'
This is exactly the problem I refered to in the issue 4709 you mentioned. Since the issue is stalled ATM, you have to define the necessary macro by yourself in distutils (using define_macros in setup.py).
Note that mingw-w64 is totally unsupported by python ATM, and you will have a hard time making it work. By far the easiest solution to build 64 bits extensions on windows is to use MS compilers (which are available for free).
cheers,
David
participants (2)
-
David Cournapeau
-
James Reynolds