如何使wxPython应用程序可以访问C ++ / wxWidgets代码?

时间:2010-06-03 00:05:03

标签: c++ python wxwidgets swig

我有一个用C ++编写的代码库,并广泛使用了wxWidgets库。我现在正在尝试包装我的库(目前正在使用SWIG),以便它可以从wxPython调用,但我已经碰壁了:

------ Build started: Project: MyLibLib, Configuration: Release_SWIG_OutputForBin Win32 ------
Performing Custom Build Step
In order to function correctly, please ensure the following environment variables are correctly set:
PYTHON_INCLUDE: C:\Python26\include
PYTHON_LIB: C:\Python26\libs\python26.lib
d:\MyProject\Software\MyLib\trunk\MyLib>C:\swigwin-2.0.0\swig.exe -python d:\MyProject\Software\MyLib\trunk\MyLibLib\MyLib.i 
d:\MyProject\Software\MyLib\trunk\MyLib>if errorlevel 1 goto VCReportError 
d:\MyProject\Software\MyLib\trunk\MyLib>goto VCEnd 
Compiling...
MyLib_wrap.c
C:\wxWidgets-2.8.10\include\wx/wxchar.h(886) : warning C4273: '_snprintf' : inconsistent dll linkage
        c:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h(358) : see previous definition of '_snprintf'
C:\wxWidgets-2.8.10\include\wx/buffer.h(127) : error C2061: syntax error : identifier 'wxCharBuffer'
C:\wxWidgets-2.8.10\include\wx/buffer.h(127) : error C2059: syntax error : ';'
C:\wxWidgets-2.8.10\include\wx/buffer.h(127) : error C2449: found '{' at file scope (missing function header?)
C:\wxWidgets-2.8.10\include\wx/buffer.h(127) : error C2059: syntax error : '}'
C:\wxWidgets-2.8.10\include\wx/buffer.h(127) : error C2059: syntax error : ')'
C:\wxWidgets-2.8.10\include\wx/buffer.h(129) : error C2061: syntax error : identifier 'wxWritableCharBuffer'
C:\wxWidgets-2.8.10\include\wx/buffer.h(129) : error C2059: syntax error : ';'
C:\wxWidgets-2.8.10\include\wx/buffer.h(129) : error C2059: syntax error : ':'
C:\wxWidgets-2.8.10\include\wx/buffer.h(134) : error C2061: syntax error : identifier 'wxWCharBuffer'
C:\wxWidgets-2.8.10\include\wx/buffer.h(134) : error C2059: syntax error : ';'
C:\wxWidgets-2.8.10\include\wx/buffer.h(134) : error C2449: found '{' at file scope (missing function header?)
C:\wxWidgets-2.8.10\include\wx/buffer.h(134) : error C2059: syntax error : '}'
C:\wxWidgets-2.8.10\include\wx/buffer.h(134) : fatal error C1004: unexpected end-of-file found
Build log was saved at "file://d:\MyProject\Software\MyLib\trunk\MyLib\Release_SWIG_OutputForBin\BuildLog.htm"
MyLibLib - 13 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我应该采用一种特殊方式吗?我花了一些时间谷歌搜索类似的错误,但没有得到任何暗示我可能在这里咆哮错误的树...?

[编辑] a dll and ctypes是答案吗?

[编辑] 我尝试在其中包含主要的wx标头,但它似乎无法解决问题:

%{
#include <wx/wx.h>
%}

我是否必须通过wxWidgets手动添加每个标头?请记住,它们中有大量的数字!

1 个答案:

答案 0 :(得分:0)

看起来您的Mylib.i未在其生成的C文件中向#include发出定义wxCharBuffer的标题等等(或者可能缺少#define s使那些包括实际执行所需的函数定义,但这不太可能)。你有所需的

%{
 #include "wxwhatever.h"
%}
您的.i文件中的

等等?你能看一下生成的.c,看看哪些包含指令存在或缺失(或者顺序错误)?

关于你正在尝试的任务,没有什么特别棘手的(我知道),编译器的错误消息只是向我建议“缺少包含或类似内容”......