我正在使用 C++ 和 wxWidgets 编写一个小游戏:
- IDE:日食
- 使用 Unity 的 Ubuntu 12.04
- wxWidgets 2.8
- glib2.0-2.34.1
我收到以下运行时错误:
(process:14421): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.34.1/./gobject /gtype.c:2720: You forgot to call g_type_init()
(process:14421): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed
(process:14421): Gdk-CRITICAL **: IA__gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed
(process:14421): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.34.1/./gobject/gtype.c:2720: You forgot to call g_type_init()
(process:14421): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed
(process:14421): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.34.1/./gobject/gtype.c:2720: You forgot to call g_type_init()
(process:14421): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.34.1/./gobject/gtype.c:2720: You forgot to call g_type_init()
(process:14421): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.34.1/./gobject/gtype.c:2720: You forgot to call g_type_init()
(process:14421): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
我做了一些研究,但我不太明白:
- g_type_init() 是做什么的?
更重要的是:
- 我必须包含哪些头文件和库,或者我的系统上可能缺少什么?
编辑 附加代码:
#include "../GUI/gui.h"
int main()
{
wxWindow myParent;
Spielfenster meinFenster(&myParent);
return 0;
}
GUI头文件:
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 21 2009)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __gui__
#define __gui__
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class Spielfenster
///////////////////////////////////////////////////////////////////////////////
class Spielfenster : public wxFrame
{
private:
protected:
wxStaticText* m_staticText6;
wxStaticText* m_staticText7;
wxStaticText* m_staticText8;
wxStaticText* m_staticText9;
wxStaticText* m_staticText10;
public:
Spielfenster( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Feuerwerk"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 600,400 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
~Spielfenster();
};
#endif //__gui__
GUI cpp 文件:
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 21 2009)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "gui.h"
///////////////////////////////////////////////////////////////////////////
Spielfenster::Spielfenster( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxVERTICAL );
wxGridSizer* gSizer3;
gSizer3 = new wxGridSizer( 1, 5, 0, 0 );
m_staticText6 = new wxStaticText( this, wxID_ANY, wxT("HandCard1"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText6->Wrap( -1 );
gSizer3->Add( m_staticText6, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
m_staticText7 = new wxStaticText( this, wxID_ANY, wxT("HandCard2"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText7->Wrap( -1 );
gSizer3->Add( m_staticText7, 0, wxEXPAND, 5 );
m_staticText8 = new wxStaticText( this, wxID_ANY, wxT("HandCard3"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText8->Wrap( -1 );
gSizer3->Add( m_staticText8, 0, wxEXPAND, 5 );
m_staticText9 = new wxStaticText( this, wxID_ANY, wxT("HandCard4"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText9->Wrap( -1 );
gSizer3->Add( m_staticText9, 0, wxEXPAND, 5 );
m_staticText10 = new wxStaticText( this, wxID_ANY, wxT("HandCard5"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText10->Wrap( -1 );
gSizer3->Add( m_staticText10, 0, wxEXPAND, 5 );
bSizer2->Add( gSizer3, 1, wxEXPAND, 5 );
this->SetSizer( bSizer2 );
this->Layout();
}
Spielfenster::~Spielfenster()
编译器调用:
g++ -D_LARGE_FILES -D__WXGTK__ -I/usr/include/wx-2.8 -I/usr/include/wx-2.8/wx/gtk -I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-release-2.8 -O0 -g3 -Wall -c -fmessage-length=0 -std=gnu++11 -pthread -MMD -MP -MF"gui.d" -MT"gui.d" -o "gui.o" "/home/michael/workspace/GUI/gui.cpp"
链接器调用:
g++ -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -pthread -L/usr/lib/wxformbuilder -o "Fireworks" ./card.o ./game.o ./gui.o ./hello.o ./set.o ./stack.o -lwx_gtk2u_richtext-2.8 -lwx_gtk2u_aui-2.8 -lwx_gtk2u_xrc-2.8 -lwx_gtk2u_qa-2.8 -lwx_gtk2u_html-2.8 -lwx_gtk2u_adv-2.8 -lwx_gtk2u_core-2.8 -lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8
我观察到的一些奇怪的事情是,Eclipse 仍然在 gui.h 和 gui.cpp 中给我错误,例如“无法解析类型'wxStaticText'”但编译......这可能是一个提示吗?
Edit2 如果我从这个站点以“helloworld 方式”执行它,它可以工作:http : //www.wxwidgets.org/docs/tutorials/hworld.txt 然后我没有得到 g_type_init() 的错误作为建议。(尚)不知道真正的区别是什么。