Search code examples
gccwxwidgetssetup-project

How to setup wxWidgets for hello world project with Code::Blocks?


I would like to use wxWidgets 3.0.2 library in my project. However I am unable to run even the hello world program. I have downloaded the headers and the appropriate binaries (TDM GCC x64 4.8.1). I've extracted them without any changes. So there are include and libs folders present in my wxWidgets folder. I am using TDM-GCC 5.1 which is setup properly. When I create a simple console application and only include the main file

#include "C:\wxWidgets\include\wx\wx.h"

I get an error

C:\wxWidgets\include\wx\wx.h|14|fatal error: wx/defs.h: No such file or directory|

Which is quite reasonable, as defs.h is in the same folder as wx.h and there is no wx folder inside. Do I need to rearrange the file structure? Is the compiler problem here (5.1 used instead of 4.8.1)? For three days I am running trough different tutorials, and all the time I get this or similar errors. How to set it up properly?

The whole code is just:

#include <iostream>

using namespace std;

#include "C:\wxWidgets\include\wx\wx.h"

int main()
{
    cout << "hello" << endl;
    return 0;
}

Solution

  • You should never include wxWidgets (or any other library) header files using full paths. Instead you should have just

    #include <wx/wx.h>
    

    in your code and set up your compiler headers search path to include c:\wxWidgets\include directory. Notice that you will also need to add c:\wxWidgets\lib\gcc481_lib\mswu or similar to the includes path, depending on the exactl configuration you're using (e.g. it could be gcc481_dll if you're using the DLL build).