2015-04-01 201 views
1

我有一個項目需要使用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。

回答

0

從SWIG文檔的第3.4段:

一個共同的問題在Windows上使用痛飲的時候是Microsoft功能 調用約定這不是C++標準。 SWIG解析ISO C/C++,因此無法處理專有約定,如 __declspec(dllimport),__stdcall等。雖然有Windows接口文件windows.i來處理這些調用約定。該 文件還包含typemaps處理常用的Windows 具體類型,如__int64,BOOL,DWORD等包括像你 任何其他接口文件,例如:

%include <windows.i> 

__declspec(dllexport) ULONG __stdcall foo(DWORD, __int32); 

之前的任何添加%include <windows.i>特定於Windows的聲明可能會解決您的問題。

+0

謝謝,這讓我進入了我認爲更好的方向。現在,當它試圖編譯成一個Python模塊時,我收到了一堆鏈接錯誤。我需要鏈接到幾個.Lib文件,但是我無法找到一個確定的答案,如果甚至可能的話...... – kjlaw89 2015-04-21 18:00:21