Undefined calling conventions in Python.h

Jaco Naude naude.jaco at gmail.com
Wed Jul 23 06:43:18 EDT 2008


On Jul 23, 12:16 pm, Fredrik Lundh <fred... at pythonware.com> wrote:
> Jaco Naude wrote:
> > good point. I agree that the problem is probably due to name mangling.
> > I'm not sure how its possible to tell the application that the DLL is
> > a C dll? I've looked at the DLL using Dependency Walker and the
> > functions in the DLL are clean (Thus no name mangling used).
>
> > How do I tell Visual C++ that the DLL is a C dll? I thought it should
> > be in Python.h but this line appears at the top of the file:
>
> > /* Since this is a "meta-include" file, no #ifdef __cplusplus / extern
> > "C" { */
>
> All the individual includes are wrapped in the usual
>
>      #ifdef __cplusplus
>      extern "C" {
>      #endif
>
> stuff, so the compiler should default to C bindings, without you having
> to do anything.  Unfortunately, I haven't used VS 2008, but I find it
> hard to believe that they've messed this up completely, and a quick
> googling indicates that people are using it with Python without trouble.
>
> Maybe there's some override in your project settings caused by some
> other parts of your project?  (or an #undef __cplusplus somewhere, perhaps?)
>
> </F>

I've figured out that the names in the DLL are not mangled by looking
into the DLL using dependancy walker. I also figured out that the
problem is on the application's side and not on the dll's side.

What Visual C++ is doing is that it is looking for mangled names since
it does not know the DLL contains C functions. I've managed to work
around this by declaring the Python functions as follows before using
them in the C++ application side:

extern "C"
{
    void Py_Initialize(void);
}

This seems to work and the C++ application side is not looking for
mangled names any more. Is this the right way of doing it? It seems
unnecessary to have to declare each Python function you want to use
using the extern "C" way as shown above.

It is probably more of a C++ question it turns out, but I would think
that someone in the Python group would use the Python DLL in C++. The
documentation also suggest that there is no extra work needed when
using C++ rather than C.

Thanks for the help so far.
Jaco



More information about the Python-list mailing list