【问题标题】:Setting up wxWidgets in Code::Blocks?在 Code::Blocks 中设置 wxWidgets?
【发布时间】:2012-01-19 16:16:29
【问题描述】:

我正在尝试使此代码正常工作,但我做不到。我希望它可以运行,以便我可以在我的其他项目中使用它。我刚在网上看到这个。这是关于 wxOGL 的。

#include <wx/wx.h>
#include <wx/ogl/ogl.h>
#include <wx/cursor.h>

class MyApp: public wxApp
{
    virtual bool OnInit();
};

class MyFrame: public wxFrame
{
    wxDiagram * diagram;
    wxShape * shape;

public:

    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    ~MyFrame();
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame(_("wxWidgets - Object Graphics Library"),
                             wxPoint(50, 50), wxSize(450, 340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
    return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
    wxShapeCanvas *canvas = new wxShapeCanvas(this, wxID_ANY, pos, size, 0, _T("a"));

    canvas->SetBackgroundColour(*wxWHITE);
    canvas->SetCursor(wxCursor(wxCURSOR_CROSS));

    diagram = new wxDiagram();

    canvas->SetDiagram(diagram);

    shape = new wxCircleShape(20.0);
    shape->SetX(25.0);
    shape->SetY(25.0);
    canvas->AddShape(shape);

    diagram->ShowAll(1);
}

MyFrame::~MyFrame()
{
    delete shape;
    delete diagram;
}

我不知道它是做什么的,我只是想看看它。当我在 Code::Blocks 中编译它时,它不断返回错误说“wx/wx.h:没有这样的文件目录”和其他错误。有谁可以解决这个问题?

【问题讨论】:

    标签: c++ wxwidgets codeblocks


    【解决方案1】:

    wx/wx.h: 没有那个文件目录"

    您的编译器找不到您的 wxWidgets 安装。 The Code::Blocks people have some documentation for setting that up.

    【讨论】:

      【解决方案2】:

      该错误意味着没有正确安装 wxWidgets 开发文件,或者您的项目设置已损坏。

      【讨论】:

        【解决方案3】:

        通常像这样的包会使用配置脚本来指定编译/链接器参数。所以如果你只是从命令行使用 gcc 编译器:

        g++ `wx-config --cflags` `wx-config --libs` -lwx_gtk2u_ogl-2.8 test.cpp -o test
        

        在 Code::Blocks 中,您只需右键单击您的项目,Build Options...,在左侧窗口中选择您的项目名称(如果在执行下一步时突出显示 Release/Debug,则更改只会用于发布或调试版本),编译器设置选项卡,其他选项选项卡,然后插入:

        `wx-config --cflags`
        

        然后选择 Linker-settings 选项卡并在 Other-linker-options 窗口中添加:

        `wx-config --libs` -lwx_gtk2u_ogl-2.8
        

        这两个东西通常会在 C::B 中为您设置(OGL 库除外)。 此外,该程序使用对象图形库 (OGL),它不是 wxWidgets 基本集的一部分,因此您还必须明确包括以下内容:

        -lwx_gtk2u_ogl-2.8

        请记住,-2.8 部分是版本号,在您的机器上可能会有所不同。假设已安装,您可以通过发出命令 (linux) 找出您拥有的版本:

        找到 /usr/lib | grep -i wx | -i ogl

        它将在您的用户库区域中查找名称中包含“wx”和“ogl”的所有文件。

        祝你好运 /艾伦

        【讨论】:

          猜你喜欢
          • 2020-05-16
          • 2013-02-20
          • 2016-07-07
          • 1970-01-01
          • 2012-06-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多