Author Topic: Help compiling a simple beginners program  (Read 7110 times)

mrpringle

  • Guest
Help compiling a simple beginners program
« on: January 06, 2007, 12:00:24 pm »
Hi,
I"m just trying to get the hang of wxWiidgets. There's a few things I don't understand, and I've had trouble compiling a basic application from scratch.
I'm using wxWidgets 2.8.0. I've got a fair understanding of command-line c++ programming, but never dealt with GUI's before.

I'm getting an error when compiling my project which says:
Basic.cpp:: undefined reference to `vtable for BasicFrame'
Basic.cpp:: undefined reference to `vtable for BasicFrame'
:: === Build finished: 2 errors, 0 warnings ===



Here is Basic.h
#ifndef BASIC_H
#define BASIC_H

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

class BasicFrame: public wxFrame
{
    public:
        BasicFrame(const wxString & title, int xpos, int ypos, int width, int height);
        ~BasicFrame();
};
#endif

___________________________________________________________________
and here is Basic.cpp

#include "basic.h"
#include <wx/wx.h>

IMPLEMENT_APP(Basic)

bool Basic::OnInit()
{
    BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
    frame->Show();
    SetTopWindow(frame);
    return true;
}

BasicFrame::BasicFrame (const wxString & title, int xpos, int ypos, int width, int height)
: wxFrame(NULL, -1, title, wxPoint (xpos,ypos), wxSize (width, height))
{}



____________________________________________________________________________
For the moment I'm just trying to get a wxFrame showing, and then I'll mess around with event handling and controls, etc.

Another thing which I'm unsure about is the use of the _ symbol on this line:
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
What does the _ in _("Sample") do?

I appreciate your time.
« Last Edit: January 06, 2007, 12:02:40 pm by mrpringle »

Offline SamT

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Help compiling a simple beginners program
« Reply #1 on: January 06, 2007, 01:23:00 pm »
I would suggest you to build up a very simple frame program by the wizard which included in C::B. Then check each line of the generated source.

I test the wizard in svn build rev 3461 and works fine for me.

mrpringle

  • Guest
Re: Help compiling a simple beginners program
« Reply #2 on: January 06, 2007, 01:27:02 pm »
I got the wizard working, but I don't really understand all the code it generates, so I followed a tutorial off the internet.
Wizards are good, but I would prefer to learn the stuff line by line before I use the wizard.

mrpringle

  • Guest
Re: Help compiling a simple beginners program
« Reply #3 on: January 06, 2007, 01:42:58 pm »
never mind. I worked out what was wrong.

Offline SamT

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Help compiling a simple beginners program
« Reply #4 on: January 06, 2007, 03:25:58 pm »
I would suggest you to study a book "Cross-Platform GUI Programming with wxWidgets" http://www.wxwidgets.org/docs/book/ However, could somebody tell me why there is only one book for wxWidgets? Did I miss something?

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Help compiling a simple beginners program
« Reply #5 on: January 06, 2007, 05:34:51 pm »
Here is Basic.h
#ifndef BASIC_H
#define BASIC_H

#include <wx/wx.h> // <-- Missing Header

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

class BasicFrame: public wxFrame
{
    public:
        BasicFrame(const wxString & title, int xpos, int ypos, int width, int height);
        ~BasicFrame();
};
#endif

Add the missing header, highlighted in red colour, in the Basic.h file.

Another thing which I'm unsure about is the use of the _ symbol on this line:
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
What does the _ in _("Sample") do?

That basically converts the char * to wxChar * which is used to construct wxString for title parameter used in frame class' constructor. But this is an advanced call. wxWidgets manual defines it in the following way.

Quote
_
const wxChar * _(const char *s)

This macro expands into a call to wxGetTranslation function, so it marks the message for the extraction by xgettext just as wxTRANSLATE does, but also returns the translation of the string for the current locale during execution.

Don't confuse this macro with _T()!


Hope this helps.  :)


P.S. - This is a Code::Blocks development related forum. So from next time please post such requests in other section.
« Last Edit: January 06, 2007, 05:41:14 pm by Biplab »
Be a part of the solution, not a part of the problem.

mrpringle

  • Guest
Re: Help compiling a simple beginners program
« Reply #6 on: January 07, 2007, 12:21:27 am »
Here is Basic.h
#ifndef BASIC_H
#define BASIC_H

#include <wx/wx.h> // <-- Missing Header

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

class BasicFrame: public wxFrame
{
    public:
        BasicFrame(const wxString & title, int xpos, int ypos, int width, int height);
        ~BasicFrame();
};
#endif

Add the missing header, highlighted in red colour, in the Basic.h file.

Another thing which I'm unsure about is the use of the _ symbol on this line:
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
What does the _ in _("Sample") do?

That basically converts the char * to wxChar * which is used to construct wxString for title parameter used in frame class' constructor. But this is an advanced call. wxWidgets manual defines it in the following way.

Quote
_
const wxChar * _(const char *s)

This macro expands into a call to wxGetTranslation function, so it marks the message for the extraction by xgettext just as wxTRANSLATE does, but also returns the translation of the string for the current locale during execution.

Don't confuse this macro with _T()!


Hope this helps.  :)


P.S. - This is a Code::Blocks development related forum. So from next time please post such requests in other section.

Thanks.