After pondering and wondering, I have decided to go for wxWidgets. Here is my first trial application. After running a test app from zetcode.com in my Code::Blocks & wxWidgets and I confirmed that it is fine! Then I tried to write my own app as shown below but I ran errors. Please correct me wher I have gone wrong, and any suggestion in the code. I'm just starting with wxWidgets
Cheers :)

#include <wx/wx.h>
class MyApp : public wxApp
{
    virtual bool OnInit();
};

class MyFrame : public wxFrame
{
    public:
        MyFrame(const wxString& title);
};

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    wxFrame *newFrame = new wxFrame(wxT("Hello Mary!"));
    newFrame->Show();
    return true;
}

MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
  Centre();
}

Errors:

C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|1|wx/wx.h: No such file or directory|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|3|error: expected class-name before '{' token|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|8|error: expected class-name before '{' token|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|10|error: expected `,' or `...' before '&' token|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|10|error: ISO C++ forbids declaration of `wxString' with no type|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|13|error: expected constructor, destructor, or type conversion before ';' token|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp||In member function `virtual bool MyApp::OnInit()':|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|17|error: `wxFrame' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|17|error: `newFrame' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|17|error: `wxFrame' is not a type|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|17|error: `wxT' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|17|warning: unused variable 'wxFrame'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|17|warning: unused variable 'wxT'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|22|error: expected `,' or `...' before '&' token|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: ISO C++ forbids declaration of `wxString' with no type|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp||In constructor `MyFrame::MyFrame(int)':|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: class `MyFrame' does not have any field named `wxFrame'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: `NULL' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: `wxID_ANY' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: `title' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: `wxDefaultPosition' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|error: `wxSize' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|25|error: `Centre' was not declared in this scope|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|25|warning: unused variable 'Centre'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|warning: unused variable 'NULL'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|warning: unused variable 'wxID_ANY'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|warning: unused variable 'title'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|warning: unused variable 'wxDefaultPosition'|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\myfirst\main.cpp|23|warning: unused variable 'wxSize'|
||=== Build finished: 19 errors, 8 warnings ===|

Dani AI

Generated

A short expert note building on the thread: the errors shown are two separate, common issues — missing wx headers (project configuration) and a constructor mismatch when creating frames. was heading the right direction: use the IDE’s wxWidgets project support so the compiler and linker get the right include/lib paths and flags. ’s later admission that a console project was used explains the initial "missing wx headers / symbols" symptoms.

A compact checklist that addresses the configuration side:

  • Use Code::Blocks’ wxWidgets project wizard (so compiler defines, search paths and linker flags are set automatically).
  • Ensure the compiler search directories include the wxWidgets top-level include folder and the build-specific include folder that contains the generated setup header.
  • Add the corresponding wxWidgets lib folder (the build-specific lib matching the compiler) to the linker search directories and link the appropriate libraries built for that compiler/runtime (MinGW vs MSVC, Unicode vs ANSI, static vs DLL).
  • Make the project a GUI/wx project (not a console target) so the correct subsystem and linker flags are used.

About the constructor error: the base wxFrame does not have a simple "single-title-only" constructor overload, so creating an instance of the derived MyFrame (the wrapper that sets parent/id/size) is the correct approach — which fixed. Relatedly, avoid editing wxWidgets library headers to silence build-time checks (as experimented). Editing library headers can mask real configuration problems; instead obtain a prebuilt binary that matches the toolchain or rebuild wxWidgets with the desired options.

After fixing include/lib paths and using the derived frame, the remaining methods like Centre() and wxString types will resolve. If linking errors follow, verify that the chosen wx build and the compiler toolchain match exactly (same compiler, same Unicode/static settings).

Recommended Answers

All 4 Replies

Compare your project settings, specifically things like additional include search paths, library search paths and libraries.

Doesn't code::blocks come with a "new wxwidgets" project tool to set all this up for you?

It doesn't compile with VC++ 2008 Express either. The compiler didn't like the preprocessor directive on line 1002, chkconf.h. So I changed it to this:

#ifdef wxUSE_CRASHREPORT
#if !wxUSE_ON_FATAL_EXCEPTION
#   ifdef wxABORT_ON_CONFIG_ERROR
#       error "wxUSE_CRASHREPORT requires wxUSE_ON_FATAL_EXCEPTION"
#   else
#       undef wxUSE_CRASHREPORT
#       define wxUSE_CRASHREPORT 0
#   endif
#endif /* wxUSE_CRASHREPORT */
#endif

After that, the compiler issued the error message on line 1819. error "wxClipboard requires wxDataObject"

Ok, I realize that. I used console instead of wxWidgets. Really I jumped on broken glass and guess what? :)

Now When I compile it gives me some sort of errors

C:\Documents and Settings\smtangoo\My Documents\C++ projects\steve\steveApp.cpp||In member function `virtual bool MyApp::OnInit()':|
C:\Documents and Settings\smtangoo\My Documents\C++ projects\steve\steveApp.cpp|17|error: no matching function for call to `wxFrame::wxFrame(const wchar_t[12])'|
C:\Program Files\CodeBlocks\wxWidgets-2.8.10\include\wx\msw\frame.h|168|note: candidates are: wxFrame::wxFrame(const wxFrame&)|
C:\Program Files\CodeBlocks\wxWidgets-2.8.10\include\wx\msw\frame.h|27|note: wxFrame::wxFrame(wxWindow*, wxWindowID, const wxString&, const wxPoint&, const wxSize&, long int, const wxString&)|
C:\Program Files\CodeBlocks\wxWidgets-2.8.10\include\wx\msw\frame.h|19|note: wxFrame::wxFrame()|
||=== Build finished: 1 errors, 0 warnings ===|

Ok I messed up line 17, it should have been

MyFrame *newFrame = new MyFrame(wxT("Hello Mary!"));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.