Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compiling extension module (linker error)

29 views
Skip to first unread message

Paul Volkov

unread,
Oct 22, 2012, 6:55:15 AM10/22/12
to pytho...@python.org
I am trying to compile an extension module with C++ Builder 6 for Python 3.3.
I converted python33.lib using coff2omf.exe and added this library
into my project.
I wonder why I get this error message while building:

[Linker Error] Unresolved external '_PyModule_Create2TraceRefs'
referenced from 'D:\WORK\FROMAGE\OUT\ROSE_UNIT.OBJ'

My source file:

//---------------------------------------------------------------------------

#include <Python.h>
#include <windows.h>
#pragma argsused

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}

static PyObject* __declspec(dllexport) testik(PyObject* self, PyObject* args)
{
return NULL;
}

static PyMethodDef FundRoseMethods[] = {
{"testik", testik, METH_VARARGS, "perform a test"},
{NULL, NULL, 0, NULL}
};

static struct PyModuleDef FundRoseModule = {
PyModuleDef_HEAD_INIT,
"FundRose",
NULL,
-1,
FundRoseMethods
};

PyMODINIT_FUNC
PyInit_FundRose(void)
{
return PyModule_Create(&FundRoseModule);
}

//---------------------------------------------------------------------------

MRAB

unread,
Oct 22, 2012, 2:03:05 PM10/22/12
to pytho...@python.org
On 2012-10-22 11:55, Paul Volkov wrote:
> I am trying to compile an extension module with C++ Builder 6 for Python 3.3.
> I converted python33.lib using coff2omf.exe and added this library
> into my project.
> I wonder why I get this error message while building:
>
> [Linker Error] Unresolved external '_PyModule_Create2TraceRefs'
> referenced from 'D:\WORK\FROMAGE\OUT\ROSE_UNIT.OBJ'
>
> My source file:
>
> //---------------------------------------------------------------------------
>
> #include <Python.h>
> #include <windows.h>
> #pragma argsused
>
It's a Python module with its own initialiser, so you don't need this:

> BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
> {
> return 1;
> }
>
You don't need to export this function because it's listed in the
module's function table:

> static PyObject* __declspec(dllexport) testik(PyObject* self, PyObject* args)
> {

Returning NULL says that an exception was raised. You should set the
exception.

> return NULL;
> }
>
> static PyMethodDef FundRoseMethods[] = {
> {"testik", testik, METH_VARARGS, "perform a test"},
> {NULL, NULL, 0, NULL}
> };
>
> static struct PyModuleDef FundRoseModule = {
> PyModuleDef_HEAD_INIT,
> "FundRose",
> NULL,
> -1,
> FundRoseMethods
> };
>
> PyMODINIT_FUNC
> PyInit_FundRose(void)
> {
> return PyModule_Create(&FundRoseModule);
> }
>
> //---------------------------------------------------------------------------
>
By the way, the recommendation is for module names to be lowercase with
underscores, so "fund_rose" instead of "FundRose".

Try this code:

#include <Python.h>
#include <windows.h>
#pragma argsused

static PyObject* testik(PyObject* self, PyObject* args)
{
PyErr_SetString(PyExc_RuntimeError, "testik exception");

Paul Volkov

unread,
Oct 23, 2012, 3:00:09 AM10/23/12
to pytho...@python.org
2012/10/22 MRAB <pyt...@mrabarnett.plus.com>:
> By the way, the recommendation is for module names to be lowercase with
> underscores, so "fund_rose" instead of "FundRose".
>
> Try this code:
>

I tried as you suggested, but the linker error (unresolved external)
is still there.
I'm sure python33.lib is properly added because if I remove it, there
are 3 errors, not 1.
By the way, what is the difference between python3.lib and python33.lib?

MRAB

unread,
Oct 23, 2012, 12:40:33 PM10/23/12
to pytho...@python.org
On 2012-10-23 08:00, Paul Volkov wrote:
> 2012/10/22 MRAB <pyt...@mrabarnett.plus.com>:
>> By the way, the recommendation is for module names to be lowercase with
>> underscores, so "fund_rose" instead of "FundRose".
>>
>> Try this code:
>>
>
> I tried as you suggested, but the linker error (unresolved external)
> is still there.

I found a reference to PyModule_Create2TraceRefs in include\modsupport.h.

> I'm sure python33.lib is properly added because if I remove it, there
> are 3 errors, not 1.
> By the way, what is the difference between python3.lib and python33.lib?
>
I don't know.

0 new messages