dsm42026 2017-09-14 11:56
浏览 83

怎样省略前向声明

I am trying to run swig on vendor header so I do not need to redefine the implementation in a separate header file

swig -go -cgo -intgosize 64 -module qt -o $WORK/qt/_obj/qt_wrap.cxx -outdir $WORK/qt/_obj/ \ 
-I$HOME/Qt5.9.1/5.9.1/gcc_64/include -I$HOME/Qt5.9.1/5.9.1/gcc_64/include/QtOpenGL \
-I$HOME/Qt5.9.1/5.9.1/gcc_64/include/QtWidgets -I$HOME/Qt5.9.1/5.9.1/gcc_64 \ 
/include/QtGui -I$HOME/Qt5.9.1/5.9.1/gcc_64/include/QtCore -c++ qt.swigcxx

I am getting the error below during go build

$HOME/Qt5.9.1/5.9.1/gcc_64/include/QtWidgets/qapplication.h:57: Error: Syntax error in input(1).

Upon inspecting

qapplication.h:57

#include <QtWidgets/qtwidgetsglobal.h>
#include <QtCore/qcoreapplication.h>
#include <QtGui/qwindowdefs.h>
#include <QtCore/qpoint.h>
#include <QtCore/qsize.h>
#include <QtGui/qcursor.h>
#ifdef QT_INCLUDE_COMPAT
# include <QtWidgets/qdesktopwidget.h>
#endif
#include <QtGui/qguiapplication.h>

QT_BEGIN_NAMESPACE


class QDesktopWidget;

Obviously fail on the forward declaration.

Below is qt.swigcxx:

// See swig.org for more inteface options,
// e.g. map std::string to Go string
%module qt
%{
#include <QPushButton>
#include <QApplication>
%}

%ignore "";


%include <qapplication.h>
%include <qpushbutton.h>

How can I change so that swig omits the forward declaration?

  • 写回答

1条回答 默认 最新

  • dongwo7858 2017-09-14 12:05
    关注

    If you really need to inform SWIG it should ignore something in the source code, you can use the macros it defines: Documentation

    So your qapplication.h changes to this:

    #include <QtWidgets/qtwidgetsglobal.h>
    #include <QtCore/qcoreapplication.h>
    #include <QtGui/qwindowdefs.h>
    #include <QtCore/qpoint.h>
    #include <QtCore/qsize.h>
    #include <QtGui/qcursor.h>
    #ifdef QT_INCLUDE_COMPAT
    # include <QtWidgets/qdesktopwidget.h>
    #endif
    #include <QtGui/qguiapplication.h>
    
    QT_BEGIN_NAMESPACE
    
    #ifndef SWIG
    class QDesktopWidget;
    #endif
    

    Be careful with this tactic in general, though, you might end up doing something to make the SWIG preprocessor succeed, but then fail the C++ compilation because you left out something important.

    Another approach is to avoid %include altogether (speaking from enterprise experience here). As your project grows large, SWIG will increasingly slow down as a result of including everything from your header files. In the end, just copying the declarations SWIG needs is worth it for the compilation times.

    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗