2012-01-12 57 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