我正在处理一个需要使用 Topaz Signature Capture 板的项目。我们的产品目前使用 Topaz 提供的 ActiveX 控件来收集网站上的签名,但我们正在尝试迁移到由 Python 提供支持的桌面应用程序。Python 将允许我们在没有太多额外工作的情况下扩展到多个操作系统。
Topaz 提供了一个“C”库 ( http://www.topazsystems.com/sigpluslibrary.html ) 用于与他们的设备交互。我相信我已经确定它实际上是 C++(使用类和其他 C++ 结构)。我尝试使用 SWIG 和 Cython 为 Python 创建一个包装器,但我运气不佳。
我的 SWIG 目录结构是这样的:
- SigSwig
- 包括(包含 Topaz 共享 C 库中的所有标题)
- 安装程序.py
- SigLib.i
- 签名.i
- ETC...
安装程序.py
# setup.py
import distutils
from 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
签名.i
%module Signature
%include "Include\Signature.h"
我很难遵循 SWIG 示例,但据我所知,这应该没问题。SigLib.i 在主头文件 (SigLib.h) 中加载,其中包括 SIGAPI 的声明和所有主包含文件。它不包括 Signature.h(或其他接口文件中的任何其他头文件),因为它不遵循所有头文件。然后它加载额外的接口文件。Signature.i 和所有其他接口文件只包含对要解析的标头的引用。
我尝试了几种不同的方法,这似乎是迄今为止最好的。但是,当我执行 setup.py 时,出现以下错误:
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 that are not pointers
SigLib_wrap.cpp(3432) : error C2275: 'TabletParameters' : illegal use of this type as an expression c:\users\kevin\downloads\sigpython\include\TabletParameters.h(18) : see declaration of 'TabletParameters'
查看生成的代码,大部分错误都包含 SIGAPI,如下所示:
SIGAPI * temp;
SIGAPI 似乎#define
出现在 SigLib.h 文件中,并用于类定义中,例如:
class SIGAPI Signature
SigLib.h 定义:
#ifdef SIGLIBDLL
#define SIGAPI __declspec( dllexport )
#else
#define SIGAPI
#endif
我已经尝试了数小时的谷歌搜索试图找到解决方案,但我没有任何运气。我无法在 SWIG 文档中找到任何内容,但老实说,我不太确定要查找什么。
编辑:
除了加载额外的标头之外,还进行了 Giorgos 建议的更改。它现在似乎生成了包含所需所有内容的整个包装文件,但链接到库时出现错误。
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"
我这样做并改变了我加载所有内容的方式。现在它似乎正在编译,但我遇到了很多这样的链接错误:
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
我需要链接 SigLib.lib 和其他一些 lib 文件,但我不确定如何从我拥有的 setup.py 文件中执行此操作,以及这是否适用于 Python。