2015-06-15 137 views
2

我努力學習wxWidgets框架,我被分配到其上已經使用庫中的項目。我使用它在樹莓派,wxWidgets的Hello World示例不編譯

已經使用sudo apt-get install libwxgtk2.8-dev libwxgtk2.8-dbg安裝它。

我發現wxWidgets的網站上this教程貼入我的皮稱爲HELLO.CPP文件。

然後我跑g++ hello.cpp -o hello WX-配置--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類型的問題。有什麼辦法可以解決這個問題嗎?看起來很奇怪,一個正式的例子會出現所有這些錯誤,我能正確編譯它嗎?

回答

2

您鏈接到wxwidgets的trunk版本的文檔。在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?

+0

這是正確的,誤差是由於使用例如具有2.8 3.0編寫。解決這個問題的另一種方法是首先使用wx 3.0,強烈推薦使用wx 3.0,但由於相當長的一段時間2.8未被維護/支持。 –