2012-01-12 139 views
1

我在编译我的wxWidgets程序时遇到问题。未编译C++ wxWidgets应用程序

#include <wx/wx.h> 
#include <wx/url.h> 
#include <wx/stream.h> 
#include <wx/sstream.h> 

int main(int argc, char* argv[]) 
{ 
    wxURL url(wxT("http://google.com")); 
    if (url.GetError()==wxURL_NOERR) 
    { 
     wxString htmldata; 
     wxInputStream *in = url.GetInputStream(); 
     if (in && in->IsOk()) 
     { 
      wxStringOutputStream html_stream(&htmldata); 
      in->Read(html_stream); 
     } 
     wxPuts(html_stream.GetString(); 
    } 


} 

当我尝试编译它,我得到以下错误:

main.cpp In function 'int main(int, char**)': 
main.cpp 8 error: 'wxURL' was not declared in this scope 
main.cpp 8 error: expected ';' before 'url' 
main.cpp 9 error: 'url' was not declared in this scope 
main.cpp 9 error: 'wxURL_NOERR' was not declared in this scope 
main.cpp 12 error: 'wxInputStream' was not declared in this scope 
main.cpp 12 error: 'in' was not declared in this scope 
main.cpp 15 error: 'wxStringOutputStream' was not declared in this scope 
main.cpp 15 error: expected ';' before 'html_stream' 
main.cpp 16 error: 'html_stream' was not declared in this scope 
main.cpp 18 error: 'html_stream' was not declared in this scope 
=== Build finished: 10 errors, 0 warnings === 

我在做什么错?我应该使用OnInit()而不是int main(),即使我想让应用程序成为控制台,非gui也是如此?

+0

您是如何编制的? – Arafangion 2012-01-12 04:24:54

+0

'wxURL'声明的名字空间是什么? – Karlson 2012-01-12 18:49:47

+0

我认为你的wx设置不正确。 wx/url.h需要定义wxUSE_URL,否则不声明wxURL。 – LiMuBei 2012-01-18 09:51:05

回答

0

看看到您setup.h文件wxWidgets的,并确保wxURL是#define作为

#define wxUSE_URL 1 

欲了解更多信息到您的安装文件(setup.h),看看http://wiki.wxwidgets.org/Setup.H

要查看wxURL的示例,请查看您的wxWidgets文件夹,转到“samples”并查看“sockets_client”。

还有备查文件在

http://docs.wxwidgets.org/2.9.3/classwx_u_r_i.html

http://wiki.wxwidgets.org/WxURL

http://wiki.wxwidgets.org/Download_a_file_from_internet