2

I'm trying to learn the wxWidgets framework as I've been assigned to work on a project which already uses the library.

I am using it on a Raspberry Pi, having installed it using sudo apt-get install libwxgtk2.8-dev libwxgtk2.8-dbg.

I found this tutorial on the wxWidgets website and pasted it into a file called hello.cpp on my Pi.

Then I ran g++ hello.cpp -o hellowx-config --cxxflags --libs` and I got the following enormous error message:

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*, ...)’

It seems that the issues around converting from char* types to wxString types. Is there any way to resolve this? It seems strange that an official example would have all these errors, am I compiling it properly?

James
  • 3,957
  • 4
  • 37
  • 82

1 Answers1

2

You linked to the documentation of the trunk Version of wxwidgets. In the wxstring, there were some changes since 2.8 to 3.0.

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

So i suggest you to use this page for the "Hello World" Programm. http://docs.wxwidgets.org/2.8.12/wx_helloworld.html#helloworld

I suggest you too, to use "g++" instead of "gcc". g++ links automaticlly to the libstdc++. What is the difference between g++ and gcc?

Community
  • 1
  • 1
schorsch_76
  • 794
  • 5
  • 19
  • This is correct, the errors are due to using example written for 3.0 with 2.8. Another way to correct this would be to use wx 3.0 in the first place which is *strongly* recommended, 2.8 is not maintained/supported since quite some time. – VZ. Jun 15 '15 at 13:41