[wxPython] Any way to build an extension module with mingw32 that works with wxPython binaries?

Hi Eric,

FWIW, I recall their being issues that prevent mixing MVC++ with the other
compilers. I thought it was a name mangling issue, but I think that would
show up when linking. It seems to be a general property of C++ compilers
that they don't play well with each other.

Tom

                    "eric"
                    <eric@scipy.org To: wxpython-users@lists.wxwindows.org
                    > cc: (bcc: Tom Fenn/US-Corporate/3M/US)
                    10/30/01 04:36 mingw32 that works with wxPython binaries?
                    PM
                    Please respond
                    to
                    wxpython-users
                                                                                                               
Hello,

I need to build an extension module that has wxWindows/wxPython code in it
using mingw32. It also needs to work with the standard wxPython binaries
(dlls) which are compiled with MSVC++. I've attached a very simple
extension module function that asks a wxFrame if it is Maximized or not.
It
will run fine if compiled with MSVC, but seg-faults if compiled with
mingw32. I've played all the tricks I know about with converting .lib
files
to .a files using tools like impdef and dllwrap, but they don't seem to
matter.

c:\wx230\lib> impdef.exe wx23_1.dll > wx23_1.def
c:\wx230\lib> dlltool --def wx23_1.def --dllname wx23_1.dll --output-lib
libwx23_1.a -k

A similar process works fine when processing python21.lib to make a
libpython21.a file. Linking to the libpython21.a file using gcc works
without a hitch. I'm guessing this is because python21.lib (and dll) are
pure C code, and wxPython is C++. Does anyone know if there are binary
compatibility issues between gcc and MSVC that come up with C++ code that
do
not exist with C code? Has anyone successfully built wxPython extension
modules with gcc that are interoperable with the standard wxPython dlls?

thanks,
eric

-------------------- simple code ----------------------------

static wxFrame* py_to_wxFrame(PyObject* py_obj,char* name)
{
    wxFrame *wx_ptr;
    if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,"_wxFrame_p"))
        handle_bad_type(py_obj,"wxFrame", name);
    return wx_ptr;
}

static PyObject* test(PyObject*self, PyObject* args, PyObject* kywds)
{
    PyObject *return_val = Py_None;
    PyObject *py_local_dict = NULL;
    static char *kwlist[] = {"a","local_dict", NULL};
    PyObject *py_a;
    py_a = NULL;

    if(!PyArg_ParseTupleAndKeywords(args,kywds,"O|O:test",kwlist,&py_a,
&py_local_dict))
       return NULL;
    try
    {
        wxFrame *a = py_to_wxFrame(py_a,"a");
        int i = a->IsMaximized();
    }
    catch( Py::Exception& e)
    {
        return_val = Py::Null();
    }
    return return_val;
}

···

Subject: [wxPython] Any way to build an extension module with

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Ok,

So from the couple of posts it sounds like linking the MSVC compiled
wxPython binaries in concert with gcc compiled code is a non-starter.
Thanks for the info.

So, the second question is: Is there any possible workaround where gcc
compiled wxPython code can co-exist in the same application with the MSVC
compiled wxPython binaries? Name mangling doesn't appear to be the issue
(things link and then seg-fault at runtime). But, because of the mention of
vtable differences, I think the answer is a resounding no. On the other
hand, I'm still hoping for a solution...

For instance, could I compile a static version of wxPython using gcc, link
my module to this? Seems like wxPython objects created by the MSVC DLL
would have the wrong vtable setup, etc. and would crash in my module.

Any other possible suggestions appreciated.

thanks,

eric

···

----- Original Message -----
From: <pfenn@mmm.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Wednesday, October 31, 2001 10:22 AM
Subject: Re: [wxPython] Any way to build an extension module with mingw32
that works with wxPython binaries?

Hi Eric,

FWIW, I recall their being issues that prevent mixing MVC++ with the other
compilers. I thought it was a name mangling issue, but I think that would
show up when linking. It seems to be a general property of C++ compilers
that they don't play well with each other.

Tom

                    "eric"
                    <eric@scipy.org To:

wxpython-users@lists.wxwindows.org

                    > cc: (bcc: Tom

Fenn/US-Corporate/3M/US)

                                         Subject: [wxPython] Any way

to build an extension module with

                    10/30/01 04:36 mingw32 that works with

wxPython binaries?

                    PM
                    Please respond
                    to
                    wxpython-users

Hello,

I need to build an extension module that has wxWindows/wxPython code in it
using mingw32. It also needs to work with the standard wxPython binaries
(dlls) which are compiled with MSVC++. I've attached a very simple
extension module function that asks a wxFrame if it is Maximized or not.
It
will run fine if compiled with MSVC, but seg-faults if compiled with
mingw32. I've played all the tricks I know about with converting .lib
files
to .a files using tools like impdef and dllwrap, but they don't seem to
matter.

c:\wx230\lib> impdef.exe wx23_1.dll > wx23_1.def
c:\wx230\lib> dlltool --def wx23_1.def --dllname wx23_1.dll --output-lib
libwx23_1.a -k

A similar process works fine when processing python21.lib to make a
libpython21.a file. Linking to the libpython21.a file using gcc works
without a hitch. I'm guessing this is because python21.lib (and dll) are
pure C code, and wxPython is C++. Does anyone know if there are binary
compatibility issues between gcc and MSVC that come up with C++ code that
do
not exist with C code? Has anyone successfully built wxPython extension
modules with gcc that are interoperable with the standard wxPython dlls?

thanks,
eric

-------------------- simple code ----------------------------

static wxFrame* py_to_wxFrame(PyObject* py_obj,char* name)
{
    wxFrame *wx_ptr;
    if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,"_wxFrame_p"))
        handle_bad_type(py_obj,"wxFrame", name);
    return wx_ptr;
}

static PyObject* test(PyObject*self, PyObject* args, PyObject* kywds)
{
    PyObject *return_val = Py_None;
    PyObject *py_local_dict = NULL;
    static char *kwlist = {"a","local_dict", NULL};
    PyObject *py_a;
    py_a = NULL;

    if(!PyArg_ParseTupleAndKeywords(args,kywds,"O|O:test",kwlist,&py_a,
&py_local_dict))
       return NULL;
    try
    {
        wxFrame *a = py_to_wxFrame(py_a,"a");
        int i = a->IsMaximized();
    }
    catch( Py::Exception& e)
    {
        return_val = Py::Null();
    }
    return return_val;
}

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

So, the second question is: Is there any possible workaround where gcc
compiled wxPython code can co-exist in the same application with the MSVC
compiled wxPython binaries? Name mangling doesn't appear to be the issue
(things link and then seg-fault at runtime).

There could be dependencies in the run-time libraries that are conflicting
or missing whenb trying to mix stuff.

But, because of the mention of
vtable differences, I think the answer is a resounding no. On the other
hand, I'm still hoping for a solution...

For instance, could I compile a static version of wxPython using gcc, link
my module to this? Seems like wxPython objects created by the MSVC DLL
would have the wrong vtable setup, etc. and would crash in my module.

If all the C++ parts (wxWindows, wxPython, your stuff) are built with gcc
then I think it would work even if they are still DLLs. wxWindows can be
built with mingw32 but a bit of work would be needed in wxPython's setup.py
to do it for wxPython as it is exepcting MSVC.

BTW, is your code including wxPython's export.h? It provides an interface
and macros for getting at some of the core routines located in wxc.pyd
without having to explicitly link to it.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!