Undefined calling conventions in Python.h
fredrik at pythonware.com
Wed Jul 23 13:10:38 CEST 2008
Jaco Naude wrote:
> 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.
Eh, are you saying that you're not including the Python.h file? Because
it does exactly that, for each and every public function in the C API.
> 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.
Oh, but I do that all the time, without doing any extra work. Both
embedding Python in C++ programs and existing it with C++ extensions.
And I'm definitely not alone.
Here's an actual session, using the version of Visual Studio I happen to
have on this machine (2003, I think) from the command line:
> more test.cc
std::cout << "world\n";
> cl cl -EHsc -MD -I \python25\include test.cc \python25\libs\python25.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
If you cannot get the same console program to work in your compiler
setup, something's wrong with your configuration.
More information about the Python-list