I am trying to port my c++ code to python by swig.
When I finish building the py, pyd, cxx and lib files, under Python (command line), I key in "module Dnld", it shows-> import error:dynamic module does not define init function. The following is my code,
Further: Add my build step to avoid misunderstanding, thank you Mark Tolonen
- File->New->Project->Windows Console Application-> Select DLL and empty project(no unicode)
- Add my SerialComm folder to the project(include DownloaderEngine.h Serial.h PortEnumerator.h,etc).
- Configuration properties->c/c++->Additional include directories->C:\Python27\include
- Configuration properties->Linker->General->Output File->$(OutDir)\Dnld.pyd
- Configuration properties->Linker->Input->Additional include directories->C:\Python27 \libs\python27.lib and .\SerialComm\setupapi.lib
- Add Dnld.i , do custom build
- Dnld.i property page->Command line->swig -c++ -python $(InputPath)
- Dnld.i property page->Output->$(InputName)_warp.cpp
- build, create Dnld_wrap.cxx, Dnld.py
- Add Dnld_wrap.cxx in my project, rebuild all, create Dnld.pyd, that's it
(Enviroment:XP SP3 with VC2008)
//DownloaderEngine.h
class __declspec(dllexport) CDownloaderEngine
{
public:
CDownloaderEngine();
virtual ~CDownloaderEngine();
signed char OpenPort(signed char _ucPort, unsigned long _ulBaudRate, unsigned char _ucParity,
unsigned char _ucStopBits,unsigned char _ucData);
....
};
//DownloaderEngine.cpp
CDownloaderEngine::CDownloaderEngine()
{
....
}
CDownloaderEngine::~CDownloaderEngine()
{
....
}
//DownloaderEngine.i
%module Dnld
%include <windows.i>
%include <std_vector.i>
%include <std_map.i>
%{
#define SWIG_FILE_WITH_INIT
#include ".\SerialComm\DownloaderEngine.h"
%}
/* Parse the header file to generate wrappers */
%include ".\SerialComm\DownloaderEngine.h"