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

#include "Python.h"
#include <iostream>

main()
{
    Py_Initialize();
    PyRun_SimpleString("print 'hello'\n");
    Py_Finalize();

    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
for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

...

> test
hello
world

If you cannot get the same console program to work in your compiler setup, something's wrong with your configuration.

</F>

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to