我从这个页面获得此代码:
http://docs.wxwidgets.org/stable/overview_helloworld.html
我刚从下面复制了代码,以了解如何从这个库开始。我从github获得了最新的代码版本并通过运行它
./configure && make && make install
一切似乎都运转正常。
现在这是我的编译器(我使用的是OSX 10.11默认编译器):
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
由于某种原因,当我运行这个时,
g++ main.cpp
wx-config --cxxflags --libs
-std=c++11
我收到此错误:
main.cpp:5:21: error: expected class name
class MyApp: public wxApp
^
main.cpp:10:23: error: unknown class name 'wxFrame'; did you mean 'MyFrame'?
class MyFrame: public wxFrame
^~~~~~~
MyFrame
main.cpp:10:7: note: 'MyFrame' declared here
class MyFrame: public wxFrame
^
main.cpp:10:23: error: base class has incomplete type
class MyFrame: public wxFrame
~~~~~~~^~~~~~~
main.cpp:10:7: note: definition of 'MyFrame' is not complete until the closing '}'
class MyFrame: public wxFrame
^
main.cpp:13:42: error: unknown type name 'wxPoint'
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
^
main.cpp:13:62: error: unknown type name 'wxSize'
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
^
main.cpp:15:18: error: unknown type name 'wxCommandEvent'
void OnHello(wxCommandEvent& event);
^
main.cpp:16:17: error: unknown type name 'wxCommandEvent'
void OnExit(wxCommandEvent& event);
^
main.cpp:17:18: error: unknown type name 'wxCommandEvent'
void OnAbout(wxCommandEvent& event);
^
main.cpp:18:5: error: C++ requires a type specifier for all declarations
wxDECLARE_EVENT_TABLE();
^
main.cpp:24:30: error: unknown type name 'wxFrame'
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
^
main.cpp:25:5: error: expected function body after function declarator
EVT_MENU(ID_Hello, MyFrame::OnHello)
^
main.cpp:32:50: error: use of undeclared identifier 'wxPoint'
MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) );
^
main.cpp:32:67: error: use of undeclared identifier 'wxSize'
MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) );
^
main.cpp:33:12: error: no member named 'Show' in 'MyFrame'
frame->Show( true );
~~~~~ ^
main.cpp:36:47: error: unknown type name 'wxPoint'
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
^
main.cpp:36:67: error: unknown type name 'wxSize'
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
^
main.cpp:39:5: error: unknown type name 'wxMenu'; did you mean 'NSMenu'?
wxMenu *menuFile = new wxMenu;
^~~~~~
NSMenu
/usr/local/include/wx-3.1/wx/defs.h:3088:28: note: 'NSMenu' declared here
DECLARE_WXCOCOA_OBJC_CLASS(NSMenu);
^
/usr/local/include/wx-3.1/wx/defs.h:3059:16: note: expanded from macro 'DECLARE_WXCOCOA_OBJC_CLASS'
typedef struct klass *WX_##klass
^
main.cpp:39:28: error: unknown type name 'wxMenu'; did you mean 'NSMenu'?
wxMenu *menuFile = new wxMenu;
^~~~~~
NSMenu
/usr/local/include/wx-3.1/wx/defs.h:3088:28: note: 'NSMenu' declared here
DECLARE_WXCOCOA_OBJC_CLASS(NSMenu);
^
/usr/local/include/wx-3.1/wx/defs.h:3059:16: note: expanded from macro 'DECLARE_WXCOCOA_OBJC_CLASS'
typedef struct klass *WX_##klass
^
main.cpp:39:28: error: allocation of incomplete type 'NSMenu'
wxMenu *menuFile = new wxMenu;
^~~~~~
/usr/local/include/wx-3.1/wx/defs.h:3088:28: note: forward declaration of 'NSMenu'
DECLARE_WXCOCOA_OBJC_CLASS(NSMenu);
^
/usr/local/include/wx-3.1/wx/defs.h:3059:16: note: expanded from macro 'DECLARE_WXCOCOA_OBJC_CLASS'
typedef struct klass *WX_##klass
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
为什么要查找MyFrame
而不使用wxFrame
?
我怎么能跑这个?
PS:我删除了这些内容:
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
如果我确实使用它们,那么我明白了:
In file included from main.cpp:5:
In file included from /usr/local/include/wx-3.1/wx/wx.h:24:
In file included from /usr/local/include/wx-3.1/wx/event.h:21:
In file included from /usr/local/include/wx-3.1/wx/cursor.h:14:
/usr/local/include/wx-3.1/wx/gdiobj.h:89:5: warning: 'GetClassInfo' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
wxDECLARE_DYNAMIC_CLASS(wxGDIObject);
^
/usr/local/include/wx-3.1/wx/rtti.h:142:5: note: expanded from macro 'wxDECLARE_DYNAMIC_CLASS'
wxDECLARE_ABSTRACT_CLASS(name);
...继续...在一个巨大的堆栈跟踪......
请帮忙吗?