<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: &#39;Times New Roman&#39;; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial,sans-serif; font-size: 13px;">Hello All,<div>
<br></div><div>I&#39;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.</div><div><br></div><div>I have taken the following steps already:</div>
<div><br></div><div><ol><li style="margin-left: 15px;">My path is set for mingw/bin as well as python31.</li><li style="margin-left: 15px;">There is a file in my disutils folder called disutils.cfg that says [build] compiler = mingw32</li>
<li style="margin-left: 15px;">The instructions in the 3.1 documentation state the following: &quot;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-</li>
<ol><li style="margin-left: 15px;"><a href="http://docs.python.org/py3k/install/index.html" target="_blank" style="color: rgb(17, 65, 112);">http://docs.python.org/py3k/install/index.html</a></li><li style="margin-left: 15px;">
I am using Python 3.1 and the latest MinGW.</li></ol><li style="margin-left: 15px;">I tested gcc/mingw by doing C:\python31&gt;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.<br>
</li><li style="margin-left: 15px;">I searched on the internet and the closest thing I can find is the following: <a href="http://bugs.python.org/issue4709" target="_blank" style="color: rgb(17, 65, 112);">http://bugs.python.org/issue4709</a></li>
<li style="margin-left: 15px;">I suspected I might be having an issue with 64 bit compatibility, but I can&#39;t get the mingw64 bit compiler to run: &quot;error: don&#39;t know how to compile C/C++ code on platform &#39;nt&#39; with &#39;x86_64-w64-mingw32-gcc&#39; compiler.<br>
</li></ol></div><div>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.<br><br></div><div>Below you will find the following</div>
<div><br></div><div>One, the error report</div><div>two,my setup.py file</div><div>three, the file I am trying to turn into a python extension module by running the following two commands:</div><div><br></div><div>python setup.py build</div>
<div>python setup.py install</div><div><br></div><div><br></div><div>#1</div><div><br></div><div><br></div><div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Microsoft Windows [Version 6.1.7600]</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Copyright (c) 2009 Microsoft Corporation.  All rights reserved.</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br></blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
c:\Python31\Lib\finance&gt;python setup.py build</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">running build</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
running build_ext</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">building &#39;finance&#39; extension</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
creating build</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">creating build\temp.win-amd64-3.1</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
creating build\temp.win-amd64-3.1\Release</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python31\include -IC:\Pytho</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">n31\PC -c finance.c -o build\temp.win-amd64-3.1\Release\finance.o</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
finance.c: In function `PyInit_finance&#39;:</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">finance.c:31: warning: implicit declaration of function `Py_Module_Create&#39;</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">finance.c:31: warning: return makes pointer from integer without a cast</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
writing build\temp.win-amd64-3.1\Release\finance.def</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">creating build\lib.win-amd64-3.1</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-3.1\Release\fin</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">ance.o build\temp.win-amd64-3.1\Release\finance.def -LC:\Python31\libs -LC:\Pyth</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">on31\PCbuild\amd64 -lpython31 -lmsvcr90 -o build\lib.win-amd64-3.1\finance.pyd</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
build\temp.win-amd64-3.1\Release\finance.o:finance.c:(.text+0x2b): undefined ref</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
erence to `_imp__PyArg_ParseTuple&#39;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">build\temp.win-amd64-3.1\Release\finance.o:finance.c:(.text+0x5c): undefined ref</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">erence to `_imp__Py_BuildValue&#39;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
build\temp.win-amd64-3.1\Release\finance.o:finance.c:(.text+0x74): undefined ref</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
erence to `Py_Module_Create&#39;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">collect2: ld returned 1 exit status</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">error: command &#39;gcc&#39; failed with exit status 1</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br></blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">c:\Python31\Lib\finance&gt;</blockquote><div><br></div><div><br></div><div>
#2</div><div><br></div><div><br></div><div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">from distutils.core import setup, Extension</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br></blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
setup(name = &quot;finance&quot;,</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">      version = &quot;1.0&quot;,</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
      ext_modules = [Extension(&quot;finance&quot;, [&quot;finance.c&quot;])])</blockquote><div><br></div><div><br></div><div>#3</div><div><br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
#include &lt;Python.h&gt;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">#include &lt;math.h&gt;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br></blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">static PyObject *</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
pdv(PyObject *self, PyObject *args)</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">{</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<span style="white-space: pre;">        </span>double value, rate, timex, denom, pdvx;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<span style="white-space: pre;">        </span>if (!PyArg_ParseTuple(args, &quot;ddd&quot;, &amp;value, &amp;rate, &amp;timex))</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<span style="white-space: pre;">                </span>return NULL;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">    denom = (double) pow ((1 + rate), (timex));</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">    pdvx = value / denom;</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<span style="white-space: pre;">        </span>return Py_BuildValue(&quot;d&quot;, pdvx);</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
}</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">PyMethodDef pdvMethods[] = {</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
    {&quot;pdv&quot;, pdv, METH_VARARGS, &quot;Returns the Present Discounted Value given of a single future value&quot;},</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
    {NULL, NULL, 0, NULL}</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">};</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br></blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">static struct PyModuleDef financemodule = {</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
   PyModuleDef_HEAD_INIT,</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">   &quot;finance&quot;,   /* name of module */</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">   NULL, /* module documentation, may be NULL */</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
   -1,       /* size of per-interpreter state of the module,</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">                or -1 if the module keeps state in global variables. */</blockquote>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">   pdvMethods</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
};</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br></blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
PyMODINIT_FUNC</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">PyInit_finance(void)</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
{</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">    return Py_Module_Create(&amp;financemodule);</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
}</blockquote><div> </div><br class="Apple-interchange-newline"></div></div></span></span>