【问题标题】:How do I make C++/wxWidgets code accessible to a wxPython app?如何使 wxPython 应用程序可以访问 C++/wxWidgets 代码?
【发布时间】:2010-06-03 00:05:02
【问题描述】:

我有一个用 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 的每个标题?请记住,它们的数量大量

【问题讨论】:

    标签: c++ python wxwidgets swig


    【解决方案1】:

    看起来您的 Mylib.i 没有在其生成的 C 文件中发送到 #include 定义 wxCharBuffer 的标头等等(或者可能缺少使这些包含实际执行所需功能的 #defines定义,但这不太可能)。你有需要的吗

    %{
     #include "wxwhatever.h"
    %}
    

    在您的.i 文件中等等?您能否查看生成的 .c 并查看存在或缺少哪些包含指令(或者可能顺序错误)?

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

    【讨论】:

      猜你喜欢
      • 2014-04-27
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      • 2021-01-27
      • 2013-10-24
      • 2018-06-16
      • 2022-09-04
      • 1970-01-01
      相关资源
      最近更新 更多