简体   繁体   English

在Code :: Blocks中设置wxWidgets?

[英]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. 关于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. 当我在Code :: Blocks中对其进行编译时,它会不断返回错误,提示“ wx / wx.h:没有这样的文件目录”和其他错误。 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: 因此,如果您仅从命令行使用gcc编译器:

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: 在Code :: Blocks中,只需右键单击项目,Build Options ...,在左侧窗口中选择项目名称(如果下一步执行时突出显示Release / Debug,则更改仅适用于(发行版或调试版),“编译器设置”标签,“其他选项”标签,并插入:

`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). 不过,通常会在C :: B中为您设置这两件事(OGL库除外)。 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: 另外,该程序使用对象图形库(OGL),它不是wxWidgets基本集的一部分,因此您还必须明确包括以下内容:

-lwx_gtk2u_ogl-2.8 -lwx_gtk2u_ogl-2.8

Keep in mind the -2.8 part is the version number which might different on your machine. 请记住,-2.8部分是您的计算机上可能不同的版本号。 You can figure out what version you have, assuming it is installed, by issuing the command (linux): 您可以通过发出命令(linux)来确定已安装的版本(假设已安装):

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

which will find all the files in your user library area with "wx" and "ogl" in their names. 它将在用户库区域中找到名称中带有“ wx”和“ ogl”的所有文件。

Good luck /Alan 祝你好运/艾伦

wx/wx.h: no such file directory" wx / wx.h:没有这样的文件目录”

Your compiler can't find your wxWidgets install. 您的编译器找不到wxWidgets安装。 The Code::Blocks people have some documentation for setting that up . Code :: Blocks人有一些文档来进行设置

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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