python - Wrapping C/C++ Library with SWIG -


i've got project i'm working on requires use of topaz signature capture pad. our product uses activex control provided topaz collecting signatures on website, we're trying move desktop application powered python. python allow branch out multiple os's without work.

topaz provides 'c' library (http://www.topazsystems.com/sigpluslibrary.html) interfacing devices. believe i've determined c++ (uses classes , other c++ constructs). i've attempted create wrapper python using swig , cython, have not had whole lot of luck.

my directory structure swig this:

  • sigswig
    • includes (contains of headers topaz shared c library)
    • setup.py
    • siglib.i
    • signature.i
    • etc...

setup.py

# setup.py import distutils distutils.core import setup, extension  module = extension(                         "_siglib",                          ["siglib.i"],                         swig_opts=['-c++'],                         language='c++',                         library_dirs=['c:\python27'],                         libraries=["siglib", "hid", "libjpeg", "libtiff", "wintab32", "wntab32x", "zlib"],                         extra_options=["siglib.lib", "hid.lib", "libjpeg.lib", "libtiff.lib", "wintab32.lib", "wntab32x.lib", "zlib.lib"]                     )  setup(       name = "signature capture",       version = "1.0",       ext_modules = [module] ) 

siglib.i

%module siglib %{ #define sigapi  #include "include\siglib.h" %}  %include tabletparameters.i %include tabletinterface.i %include lcdinterface.i %include signature.i 

signature.i

%module signature %include "include\signature.h" 

i'm having hard time following swig examples, can tell should okay. siglib.i loads in main header (siglib.h), includes declarations sigapi , of main include files. doesn't include signature.h (or of other headers in other interface files) since doesn't follow headers. loads in additional interface files. signature.i, , of other interface files include reference header parse.

i've tried few different ways , seems have been best far. however, when execute setup.py, these errors:

siglib_wrap.cpp(3417) : error c2065: 'temp' : undeclared identifier siglib_wrap.cpp(3418) : error c2065: 'temp' : undeclared identifier siglib_wrap.cpp(3418) : error c2059: syntax error : '*' siglib_wrap.cpp(3419) : error c2513: 'tabletparameters' : no variable declared before '=' siglib_wrap.cpp(3419) : error c2065: 'temp' : undeclared identifier siglib_wrap.cpp(3420) : error c2065: 'temp' : undeclared identifier siglib_wrap.cpp(3420) : error c2541: 'delete' : cannot delete objects not pointers siglib_wrap.cpp(3432) : error c2275: 'tabletparameters' : illegal use of type expression c:\users\kevin\downloads\sigpython\include\tabletparameters.h(18) : see declaration of 'tabletparameters' 

looking @ generated code, of errors contain sigapi, this:

sigapi * temp; 

sigapi appears #define occurs in siglib.h file , used in class definitions like:

class sigapi signature 

siglib.h definition:

#ifdef  siglibdll #define sigapi  __declspec( dllexport )  #else #define sigapi #endif 

i've tried hours of googling trying find solution this, haven't had luck. haven't been able find in swig documentation on it, i'm not sure for.

edit:

made change giorgos suggested in addition loading in headers. appears generate entire wrap file needed, gets errors linking libraries.

siglib.i

%module siglib %{     #include "include\siglib.h" %}   %include <windows.i> %include "include\siglib.h" %include "include\sigpoint.h" %include "include\sigstroke.h" %include "include\tabletparameters.h" %include "include\circularbuffer.h" %include "include\serialioif.h" %include "include\hidioif.h" %include "include\usbioif.h" %include "include\socketioif.h" %include "include\newsocketioif.h" %include "include\simioif.h" %include "include\processserialdata.h" %include "include\capturesig.h" %include "include\tabletpoint.h" %include "include\pointbuffer.h" %include "include\tabletinterface.h" %include "include\tabletsamplelist.h" %include "include\sigwindowtype.h" %include "include\sigfile.h" %include "include\md5.h" %include "include\utilities.h" %include "include\hotspot.h" %include "include\hotspotlist.h" %include "include\bitmapcharacter.h" %include "include\charactermap.h" %include "include\tiffimage.h" %include "include\lcdgraphicbitmap.h" %include "include\lcdinterface.h" 

i did , changed how loaded in. appears compiling, i'm getting many linking errors these:

siglib_wrap.obj : error lnk2019: unresolved external symbol "public: int __thiscall tabletinterface::pointsinpointbuffer(void)" (?pointsinpointbuffer@tabletinterface@@qaehxz) referenced in function __wrap_tabletinterface_pointsinpointbuffer  siglib_wrap.obj : error lnk2019: unresolved external symbol "public: void __thiscall tabletinterface::initprocessinputdata(void)" (?initprocessinputdata@tabletinterface@@qaexxz) referenced in function __wrap_tabletinterface_initprocessinputdata  siglib_wrap.obj : error lnk2019: unresolved external symbol "public: void __thiscall tabletinterface::closeprocessinputdata(void)" (?closeprocessinputdata@tabletinterface@@qaexxz) referenced in function __wrap_tabletinterface_closeprocessinputdata 

i need link against siglib.lib , few other lib files, i'm not sure how setup.py file have , if work python.

from paragraph 3.4 of swig documentation:

a common problem when using swig on windows microsoft function calling conventions not in c++ standard. swig parses iso c/c++ cannot deal proprietary conventions such __declspec(dllimport), __stdcall etc. there windows interface file, windows.i, deal these calling conventions though. file contains typemaps handling commonly used windows specific types such __int64, bool, dword etc. include other interface file, example:

%include <windows.i>  __declspec(dllexport) ulong __stdcall foo(dword, __int32); 

adding %include <windows.i> before windows specific declarations sovle problem.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -