简体   繁体   中英

Setting up wxWidgets in Code::Blocks?

I'm trying to make this code work but I can't. I'm hoping that it could run so I can use it in my other project. I just saw this on the web. It is about 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;
}

I don't know what it does, I just want to take a look at it. When I compile it in Code::Blocks, it keeps returning error saying "wx/wx.h: no such file directory" and other errors. Does anyone can fix this?

Often packages like this will use config scripts to specify the compile/linker parameters. So if you are just using the gcc compiler from the command line:

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

In Code::Blocks you just right-click your project, Build Options..., select the name of your project in the left hand window (if Release/Debug are highlighted when you do the next step the changes will only be for either the Release or Debug version), Compiler-Settings tab, Other-options tab, and insert:

`wx-config --cflags`

Then choose Linker-settings tab and in the Other-linker-options window add:

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

These two things would normally be set up for you in C::B though (except for the OGL library). In addition this program uses the Object Graphics Library (OGL) which isn't part of the basic set for wxWidgets so you'll have to explicitly include the following as well:

-lwx_gtk2u_ogl-2.8

Keep in mind the -2.8 part is the version number which might different on your machine. You can figure out what version you have, assuming it is installed, by issuing the command (linux):

find /usr/lib | grep -i wx | -i ogl

which will find all the files in your user library area with "wx" and "ogl" in their names.

Good luck /Alan

wx/wx.h: no such file directory"

Your compiler can't find your wxWidgets install. The Code::Blocks people have some documentation for setting that up .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM