簡體   English   中英

wxWidgets Hello World 示例未編譯

[英]wxWidgets Hello World example not compiling

我正在嘗試學習wxWidgets框架,因為我被分配到一個已經使用該庫的項目上工作。

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

我在 wxWidgets 網站上找到了這個教程,並將其粘貼到我的 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類型的問題。 有沒有辦法解決這個問題? 官方示例會出現所有這些錯誤似乎很奇怪,我是否正確編譯了它?

你鏈接到wxwidgets的trunk版本的文檔。 在 wxstring 中,從 2.8 到 3.0 有一些變化。

http://docs.wxwidgets.org/trunk/overview_changes_since28.html

因此,我建議您將此頁面用於“Hello World”程序。 http://docs.wxwidgets.org/2.8.12/wx_helloworld.html#helloworld

我也建議您使用“g++”而不是“gcc”。 g++ 自動鏈接到 libstdc++。 g++ 和 gcc 有什么區別?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM