Yes, even though you have "/export:initexample" in the vcproj file for the provided example, the problem is still there when importing the compiled DEBUG version of module in the python interpreter.  I'll state again what that problem is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initexample)

Subject: Re: Unable to init function during import of debug version of extension
Date: Sat, 2 Aug 2008 13:59:41 +0100

In the vcproj file for example I have the following:


Make sure you are also have this /export:initcinterpreter in your vcproj file.


On Aug 1, 2008, at 08:13, <> <> wrote:

An update:
The same import error also happens with the debug versions of the example module in the Demo.  So I added
extern "C" void initexample_d();
to python.cxx.  This built, but when import example_d with python, same problem.
So then I added initexample_d to the EXPORTS in the export definition file, which built fine, but same problem.
This is on Vista, with Visual C++.


Date: Thu, 31 Jul 2008 17:04:17 -0700

Below is a very simple extension, mostly cut from the provided example.  It compiles and builds the cinterpreter.pyd without error, but when I do the following in python:
import cinterpreter

I get this result:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initcinterpreter)

I looked over the example again and again, and I simply cannot see what the problem is.  What is wrong?


#ifdef _MSC_VER
// disable warning C4786: symbol greater than 255 character,
// nessesary to ignore as <map> causes lots of warning
#pragma warning(disable: 4786)

#include "CXX/Objects.hxx"
#include "CXX/Extensions.hxx"

#include <assert.h>

#include <algorithm>
#include <iostream>

class cinterpreter_module : public Py::ExtensionModule<cinterpreter_module>
        : Py::ExtensionModule<cinterpreter_module>( "cinterpreter" )
        add_varargs_method("test", &cinterpreter_module::c_test, "test() is just a test.");

        initialize( "cinterpreter module initialize." );

        Py::Dict d( moduleDictionary() );

    virtual ~cinterpreter_module() {}


   Py::Object c_test(const Py::Tuple &args) {
        std::cout << "c_test() called." << std::endl;
        return Py::None();

extern "C" void initcinterpreter()

    static cinterpreter_module* cinterpreter = new cinterpreter_module;

// symbol required for the debug version
extern "C" void initcinterpreter_d()
{ initcinterpreter(); }

This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
CXX-Users mailing list