Reputation: 623
I'm using distutils, and have a module spammodule.c that compiles,links and works perfectly.
But if I rename that module to .cpp and re-run the distutils build/install sequence, the module builds but gives me an error on import in python:
ImportError: dynamic module does not define init function (initspam)
Is there a different format for new modules in CPP rather than C ?
Upvotes: 3
Views: 172
Reputation: 88711
You need to enclose your init function within
#ifdef __cplusplus
extern "C" {
#endif
//initspam goes here
#ifdef __cplusplus
}
#endif
in order to prevent its name from getting mangled.
Upvotes: 6