2017-09-14 73 views
2

我試圖運行痛飲對供應商的頭,所以我並不需要重新實施在一個單獨的頭文件如何痛飲省略向前聲明

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 

我收到以下錯誤時go build

​​

在檢查

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; 

前向聲明顯然失敗。

下面是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> 

我怎樣才能改變使痛飲省略了向前聲明?

回答

2

如果你真的需要通知痛飲應該忽略在源代碼中的東西,你可以用它定義了宏:Documentation

所以你qapplication.h更改爲:

#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 

要儘管小心這種策略,但是,最終可能會讓SWIG預處理器成功,但是由於您遺漏了一些重要的東西而導致C++編譯失敗。

另一種方法是完全避免%include(從這裏的企業經驗來講)。隨着項目規模的擴大,由於包含頭文件中的所有內容,SWIG會越來越慢。最後,複製SWIG需要的聲明對於編譯時間是值得的。

+0

謝謝。我更喜歡第二個選項,現在卡住了typemap – user642318

+0

你得到這個錯誤的原因是由於SWIG無法遞歸頭文件。如果你對接口非常嚴格(避免僅包含頭文件),並且按照需要的順序包含頭文件,SWIG可用於包裝相當大的項目。我使用近40,000行生成的代碼工作在一個項目上。 SWIG零件的構建方式比QT的東西快 –