如何使WXPython应用程序访问C++ + WxWIDGET代码?

2024-07-08 09:55:29 发布

您现在位置:Python中文网/ 问答频道 /正文

<>我有一个代码库,用C++编写,并广泛使用WXWIDGET库。我现在正在尝试包装我的库(当前使用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?在

[Edit]我尝试在其中包含主wx头,但似乎无法解决问题:

^{pr2}$

我是不是要检查并手动添加wxWidgets中的每个头文件?记住,他们的数量是巨大的!在


Tags: buildincludemyprojectbuffersoftwareerrorfileswig
1条回答
网友
1楼 · 发布于 2024-07-08 09:55:29

看起来您的Mylib.i没有在其生成的C文件中向#include发送定义wxCharBuffer等的头(或者可能缺少使这些include实际执行所需函数定义的#define,但这种可能性较小)。你有需要的吗

%{
 #include "wxwhatever.h"
%}

在你的.i文件中等等?您能看看生成的.c并看看有哪些include指令存在或缺失(或者可能顺序错误)?在

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

相关问题 更多 >

    热门问题