【问题标题】:C++ wxWidgets application not compilingC ++ wxWidgets应用程序未编译
【发布时间】:2012-01-12 04:17:52
【问题描述】:

我在编译我的 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 ?

【问题讨论】:

  • 声明wxURL的命名空间是什么?
  • 我认为您的 wx 设置不正确。 wx/url.h需要定义wxUSE_URL,否则不声明wxURL。

标签: c++ wxwidgets


【解决方案1】:

查看 wxWidgets 的 setup.h 文件并确保 wxURL 为 #define as

#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

【讨论】:

    猜你喜欢
    • 2015-05-18
    • 1970-01-01
    • 2011-11-25
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2014-03-16
    相关资源
    最近更新 更多