我有一个项目需要使用Topaz签名捕获板。我们的产品目前使用Topaz提供的ActiveX控件来收集网站上的签名,但我们正在尝试转向由Python支持的桌面应用程序。 Python将允许我们在没有太多额外工作的情况下分支到多个操作系统。使用SWIG包装C/C++库
Topaz提供一个'C'库(http://www.topazsystems.com/sigpluslibrary.html)用于连接他们的设备。我相信我确定它实际上是C++(使用类和其他C++构造)。我试图使用SWIG和Cython为Python创建一个包装器,但我没有得到很多运气。
我对夜风目录结构是这样的:
- SigSwig
- 包括(包含所有自黄玉共享C库的头文件)
- setup.py
- SigLib.i
- Signature.i
- etc ...
Setup.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
Signature.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)" ([email protected]@@QAEHXZ) referenced in function __wrap_TabletInterface_PointsInPointBuffer
SigLib_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall TabletInterface::InitProcessInputData(void)" ([email protected]@@QAEXXZ) referenced in function __wrap_TabletInterface_InitProcessInputData
SigLib_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall TabletInterface::CloseProcessInputData(void)" ([email protected]@@QAEXXZ) referenced in function __wrap_TabletInterface_CloseProcessInputData
我需要链接SigLib.lib和其他几个lib文件,但我不知道如何从setup.py文件中获得该文件,如果这样做甚至可以用于Python。
谢谢,这让我进入了我认为更好的方向。现在,当它试图编译成一个Python模块时,我收到了一堆链接错误。我需要链接到几个.Lib文件,但是我无法找到一个确定的答案,如果甚至可能的话...... – kjlaw89 2015-04-21 18:00:21