wxWidgets Hello World示例未编译

时间:2015-06-15 09:20:11

标签: c++ wxwidgets

我正在尝试学习wxWidgets框架,因为我已被分配到已经使用该库的项目上工作。

我在Raspberry Pi上使用它,使用sudo apt-get install libwxgtk2.8-dev libwxgtk2.8-dbg安装它。

我在wxWidgets网站上找到了this教程,并将其粘贴到我的Pi上名为hello.cpp的文件中。

然后我运行g++ hello.cpp -o hello wx-config --cxxflags --libs`并收到以下巨大的错误消息:

gcc hello.cpp -o hello `wx-config --cxxflags --libs`
hello.cpp:20:27: error: ISO C++ forbids declaration of ‘wxDECLARE_EVENT_TABLE’ with no type [-fpermissive]
hello.cpp:27:5: error: expected constructor, destructor, or type conversion before ‘wxEventTableEntry’
hello.cpp: In member function ‘virtual bool MyApp::OnInit()’:
hello.cpp:34:84: error: conversion from ‘const char [12]’ to ‘const wxString’ is ambiguous
hello.cpp:34:84: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [12]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [12]’ to ‘int’
hello.cpp:15:5: error:   initializing argument 1 of ‘MyFrame::MyFrame(const wxString&, const wxPoint&, const wxSize&)’
hello.cpp: In constructor ‘MyFrame::MyFrame(const wxString&, const wxPoint&, const wxSize&)’:
hello.cpp:43:74: error: conversion from ‘const char [17]’ to ‘const wxString’ is ambiguous
hello.cpp:43:74: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [17]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [17]’ to ‘int’
/usr/include/wx-2.8/wx/menu.h:62:17: error:   initializing argument 2 of ‘wxMenuItem* wxMenuBase::Append(int, const wxString&, const wxString&, wxItemKind)’
hello.cpp:49:40: error: conversion from ‘const char [6]’ to ‘const wxString’ is ambiguous
hello.cpp:49:40: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [17]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [17]’ to ‘int’
/usr/include/wx-2.8/wx/menu.h:62:17: error:   initializing argument 2 of ‘wxMenuItem* wxMenuBase::Append(int, const wxString&, const wxString&, wxItemKind)’
hello.cpp:49:40: error: conversion from ‘const char [6]’ to ‘const wxString’ is ambiguous
hello.cpp:49:40: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
hello.cpp:20:27: error: ISO C++ forbids declaration of ‘wxDECLARE_EVENT_TABLE’ with no type [-fpermissive]
hello.cpp:27:5: error: expected constructor, destructor, or type conversion before ‘wxEventTableEntry’
hello.cpp: In member function ‘virtual bool MyApp::OnInit()’:
hello.cpp:34:84: error: conversion from ‘const char [12]’ to ‘const wxString’ is ambiguous
hello.cpp:34:84: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [12]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [12]’ to ‘int’
hello.cpp:15:5: error:   initializing argument 1 of ‘MyFrame::MyFrame(const wxString&, const wxPoint&, const wxSize&)’
hello.cpp: In constructor ‘MyFrame::MyFrame(const wxString&, const wxPoint&, const wxSize&)’:
hello.cpp:43:74: error: conversion from ‘const char [17]’ to ‘const wxString’ is ambiguous
hello.cpp:43:74: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [17]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [17]’ to ‘int’
/usr/include/wx-2.8/wx/menu.h:62:17: error:   initializing argument 2 of ‘wxMenuItem* wxMenuBase::Append(int, const wxString&, const wxString&, wxItemKind)’
hello.cpp:49:40: error: conversion from ‘const char [6]’ to ‘const wxString’ is ambiguous
hello.cpp:49:40: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [6]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [6]’ to ‘int’
/usr/include/wx-2.8/wx/gtk/menu.h:27:18: error:   initializing argument 2 of ‘virtual bool wxMenuBar::Append(wxMenu*, const wxString&)’
hello.cpp:50:40: error: conversion from ‘const char [6]’ to ‘const wxString’ is ambiguous
hello.cpp:50:40: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [6]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [6]’ to ‘int’
/usr/include/wx-2.8/wx/gtk/menu.h:27:18: error:   initializing argument 2 of ‘virtual bool wxMenuBar::Append(wxMenu*, const wxString&)’
hello.cpp:53:44: error: conversion from ‘const char [22]’ to ‘const wxString’ is ambiguous
hello.cpp:53:44: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [22]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [22]’ to ‘int’
/usr/include/wx-2.8/wx/frame.h:110:18: error:   initializing argument 1 of ‘virtual void wxFrameBase::SetStatusText(const wxString&, int)’
hello.cpp: In member function ‘void MyFrame::OnAbout(wxCommandEvent&)’:
hello.cpp:62:66: error: conversion from ‘const char [40]’ to ‘const wxString’ is ambiguous
hello.cpp:62:66: note: candidates are:
/usr/include/wx-2.8/wx/string.h:692:3: note: wxString::wxString(wxChar, size_t) 
/usr/include/wx-2.8/wx/string.h:692:3: note:   no known conversion for argument 1 from ‘const char [40]’ to ‘wxChar {aka wchar_t}’
/usr/include/wx-2.8/wx/string.h:682:3: note: wxString::wxString(int) 
/usr/include/wx-2.8/wx/string.h:682:3: note:   no known conversion for argument 1 from ‘const char [40]’ to ‘int’
/usr/include/wx-2.8/wx/msgdlg.h:70:17: error:   initializing argument 1 of ‘int wxMessageBox(const wxString&, const wxString&, long int, wxWindow*, int, int)’
hello.cpp: In member function ‘void MyFrame::OnHello(wxCommandEvent&)’:
hello.cpp:66:47: error: cannot convert ‘const char*’ to ‘const wxChar* {aka const wchar_t*}’ for argument ‘1’ to ‘void wxLogMessage(const wxChar*, ...)’

似乎有关从char*类型转换为wxString类型的问题。有什么方法可以解决这个问题吗?一个官方的例子会有所有这些错误似乎很奇怪,我编译得恰当吗?

1 个答案:

答案 0 :(得分:2)

您链接到中继版本的wxwidgets的文档。在wxstring中,从2.8到3.0有一些变化。

请参阅http://docs.wxwidgets.org/trunk/overview_changes_since28.html

所以我建议你将这个页面用于" Hello World" PROGRAMM。 http://docs.wxwidgets.org/2.8.12/wx_helloworld.html#helloworld

我也建议你使用" g ++"而不是" gcc"。 g ++自动链接到libstdc ++。 What is the difference between g++ and gcc?