Re: Compiling extension module (linker error)

Discussion in 'Python' started by MRAB, Oct 22, 2012.

  1. MRAB

    MRAB Guest

    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");
    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, Oct 22, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    543
    Niklas Norrthon
    Dec 7, 2005
  2. Replies:
    4
    Views:
    4,867
    Default User
    Feb 10, 2006
  3. Paul Volkov
    Replies:
    0
    Views:
    155
    Paul Volkov
    Oct 22, 2012
  4. Paul Volkov
    Replies:
    0
    Views:
    137
    Paul Volkov
    Oct 23, 2012
  5. MRAB
    Replies:
    0
    Views:
    164
Loading...

Share This Page