Using wxWidgets Pre-Built Binary in CodeBlocks

From WxWiki
Jump to: navigation, search

Introduction

For those who are not interested in building the library yourself & wants to use the pre-built binaries instead, this is how you do it in Code:Blocks

Getting the binaries

At the time this guide is written, binary releases are only available for Visual C++ and TDM-GCC. I'm doing this on Code:Blocks 16.01 with TDM-GCC v4.9.2.

  1. Go to wxWidgets Downloads page
  2. Look for the Binaries section of the release you wish to use, and click on wxMSW DLLs
  3. Download the following.
    1. Vvv is the version of wxWidgets you want to use, eg. in my case it will be 3.0.3
    2. XXX is the version of compiler you are using, eg. in my case it will be 492TDM
      1. wxWidgets-Vvv_Headers.7z
      2. wxMSW-Vvv_gccXXX_Dev.7z
      3. wxMSW-Vvv_gccXXX_ReleaseDLL.7z (optional)
  4. Extract all 3 files to a folder. I am using C:\wxWidgets_include\
    Library file extraction folder
  5. Contents of each folder
    1. Folder .\include contains header files for development.
    2. Folder .\lib\gcc492TDM_dll_Dev contains library binaries for both development and distribution.
    3. Folder .\lib\gcc492TDM_dll_Release contains DLLs for distribution only. This is not really needed as it's contents are already available in the development library binaries folder.

Linking binary to project file

Prepare a new project

  1. Start with an empty project
  2. Go to Project>Properties
  3. Under Build targets tab,
    1. For both Debug and Release target, change Type to GUI application
    2. Click OK
      Set project type as "GUI application"
  4. Go to Settings>Global variables
    1. Create a global variable which points to wxWidgets include & library binary. Here I am using wxdir.
      Add global variable "wxdir" pointing to wxWidgets include & library binary
  5. Click Close.
  6. Go to C/C++ parser options.
  7. Under Additional Search Paths, add $(#wxdir.include)
    Add wxWidgets include folder to parser search path
  8. Go to Project>Build options
    Project build options
  9. Add the following
    1. Under (Project name)->Compiler Settings->Other compiler options (These are not compulsory)
      1. -pipe
      2. -mthreads
    2. Under (Project name)->Compiler Settings->#defines (Reference Preprocessor Symbols)
      1. __GNUWIN32__
      2. __WXMSW__
      3. wxUSE_UNICODE
    3. Under (Project name)-Debug->Compiler Settings->#defines (Reference Debugging macros)
      1. __WXDEBUG__
  10. Click OK

Add library directory to project

  1. Here instead of adding the full library directory path to the project, the previously added IDE global variable will be used
  2. Go to Project>Build options
  3. Under (Project name)->Search directories
    Add lib directory using global variable "wxdir"
    1. Under Compiler tab
      1. Add $(#wxdir.BASE)
    2. Under Resource compiler tab
      1. Add $(#wxdir.BASE)
  4. Under (Project name)-Debug->Search directories
    1. Under Compiler tab
      1. Add $(#wxdir.LIB)\mswud
    2. Under Linker tab
      1. Add $(#wxdir.LIB)
    3. Under Resource compiler tab
      1. Add $(#wxdir.LIB)\mswud
  5. Under (Project name)-Release->Search directories
    1. Under Compiler tab
      1. Add $(#wxdir.LIB)\mswu
    2. Under Linker tab
      1. Add $(#wxdir.LIB)
    3. Under Resource compiler tab
      1. Add $(#wxdir.LIB)\mswu
  6. Click OK

Link library files to project

  1. Here we will add just the bare necessities. Refer to Library List to see any other libraries you will need
    1. Under (Project name)-Debug->Linker settings
      Add library files
      1. Add libwxmsw30ud_core.a
      2. Add libwxbase30ud.a
    2. Under (Project name)-Release->Linker settings
      1. Add libwxmsw30u_core.a
      2. Add libwxbase30u.a
  2. Click OK

Save and build the project

The project file is now ready. Add your source files and build it.

Distributing your program

Precompiled DLL needed to run executable

The resultant program will require the precompiled release DLLs to run. Copy the required files from .\lib\gcc492TDM_dll_Release to your executable's folder. The same files can be found in .\lib\gcc492TDM_dll_Dev too, but this can be a little messy.

Executable running with precompiled DLL