Setting up a wxWidgets project on Windows using NetBeans 6.0 is quite harder than doing the same on Linux, but if you want to be able to use the powerful features of NetBeans instead of smaller IDEs like wxDev-cpp, here is a quick guide to setup your environment. The first thing you will need is to setup MinGW and MSYS to compile wxWidgets:

  1. Download and install MinGW if you don’t already have it. Add MinGW’s bin subdirectory to your PATH environment variable. Note that if you use Vista, you must override GCC’s utilities with their corresponding Vista builds;
  2. Download and install MSYS - you will need it to compile wxWidgets. Add its bin subdirectory to PATH as you did with MinGW;
  3. Open the MSYS console and navigate to the directory where you extracted wxWidgets (or where the installation put the files from wxWidgets);
  4. Create a directory for your build (mkdir build-static-debug) and navigate to it. You may want to use other names;
  5. Run configure with your preferred options, which may include
    • --enable-debug - enable debugging info
    • --enable-optimise - create optimised code
    • --disable-shared - create static libraries (use this unless you want to distribute wxWidgets dlls with your application)
    • --enable-unicode - compile wxWidgets with unicode support

    When you are done choosing, enter the configure command. In my build, I used ../configure --enable-debug --disable-shared --enable-unicode. After configure is done, it will output the basic options of your build

  6. Run make to build wxWidgets. As this may take quite a while, you may consider doing 100 push-ups to burn the calories of that burrito you’ve just eaten while following this guide;
  7. Remove object files with rm *.o (you’re not going to need them);
  8. Run make install to install wxWidgets;

This is it for compiling wxWidgets. Now you need to setup a C/C++ project on NetBeans to use what you’ve just compiled:

  1. First of all, make sure NetBeans recognizes your MinGW + MSYS setup. Go to Tools --> Options, then select C/C++. Check if MinGW and MSYS bin subdirectories are listed on the current path list. Add them if they aren’t. make should be found inside MSYS while gcc, g++ and gdb should be found inside MinGW;
  2. Now that NetBeans recognizes your MinGW + MSYS setup, it’s time to create a new wxWidgets project. Go to File --> New Project... and select C/C++ application;
  3. With your project open, enter the project properties dialog;
  4. Select C/C++ --> C++ Compiler --> General options;
  5. Open the MSYS console and navigate to the directory where you’ve made your wxWidgets build (e.g. build-static-debug) and enter wx-config --cxxflags. wx-config will output the compiler flags for your project. On my machine wx-config --cxxflags outputs -I/c/wxWidgets-2.8.7/msw-debug/lib/wx/include/msw-uni
    code-debug-static-2.8 -I/c/wxWidgets-2.8.7/include -I/c/wxWidgets-2.8.7/contrib/include
    -D__WXDEBUG__ -D__WXMSW__ -mthreads
    . Remember to leave this console open;
  6. Add all directories preppended with -I from wx-config output to the include directories of your project;
  7. Select Command line and put the remaining flags from wx-config there;
  8. Now select Linker --> General options;
  9. Back on the MSYS console, type wx-config --libs. wx-config will output the linker flags for your project. On my machine wx-config --libs outputs -L/c/wxWidgets-2.8.7/msw-debug/lib -mthreads -Wl,–subsystem,windows -mwindows /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_richtext-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_aui-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_xrc-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_qa-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_html-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_adv-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_core-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_baseud_xml-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_baseud_net-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_baseud-2.8.a -lwxregexud-2.8 -lwxexpatd-2.8 -lwxtiffd-2.8 -lwxjpegd-2.8 -lwxpngd-2.8 -lwxzlibd-2.8 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi3;
  10. Add the directory preppended with -L to the Additional library directories inside General options and click OK to close this dialog;
  11. Now select Linker --> Libraries --> Add option... --> Other option...;
  12. Back on the MSYS console, copy the remaining linker flags;
  13. Paste the remaining flags from wx-config --libs on your notepad and replace all occurrences of /c/ by C\:/ (this letter may vary depending on where you installed wxWidgets), then paste the result on that field. Remember: replacing /c/ by C\:/ is utterly necessary if you don’t want to see ugly linker errors!;
  14. Create a simple wx program and build it;

That’s a lot of work for a first application, but for your next applications all you will have to do is to repeat the compiler and linker options. Now you can use your favorite IDE to make wxWidgets applications on Windows.

PS: A wxWidgets plugin for NetBeans (wxMatisse?) would be great.

This entry was posted on Saturday, February 23rd, 2008 at 11:35 pm and is filed under C++, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

7 Responses to “wxWidgets on Windows using NetBeans 6.0 with MinGW + MSYS”

  1. I really want to start developing Windows Applications using C++, NetBeans and wxWidgets. Having followed this guide I dont seem to be getting anywhere.

    For a tutorial that started off being rather informative, I think you’ve got lazy at the end. Step 13 especially makes no sense to me and I dont have a clue what to do there. If you’d be able to clear up that step I could give you the error messages that I get.

    I’m running Vista Ultimate, NetBeans 6, wxWidgets 2.8.7 which compiles fine using your steps

    PS: I’ve overwritten the Vista GCCs as your guide says but that doesnt help

     
  2. Hi,
    My name is James Branam and I’m the NetBeans Community Docs Manager. Your blog entry would make a fantastic tutorial for our Community Docs wiki (http://wiki.netbeans.org/wiki/view/CommunityDocs). Would you be willing to contribute it? If you need any help or have any questions, please contact me at james.branam@sun.com. I look forward to hearing from you.

     
  3. Biffy,

    Thank you very much for your input. That step was about adding a new option to your makefile to allow wxWidgets’ linker options to be used at link time, but now I’ve found a better way that does not require you to modify any makefile, so the guide will be updated to reflect this new method.

    EDIT: The guide was updated as of March 1st.

     
  4. wxWidgets on Windows using NetBeans 6.0 with MinGW + MSYS…

    […]This guide explains how to create a wxWidgets project using NetBeans on Windows (including Vista). It is divided in two parts: the first lists the steps necessary to compile wxWidgets on Windows (using MinGW + MSYS); the second part explains how t…

     
  5. Note: this tutorial was updated as of May 18th on the 13th item of the second list. I realized that if you don’t replace all occurrences of /c/ by C\:/ the include directories won’t be considered.

     
  6. I did everything exactly as explained, but I keep getting undefined references … and then the build is failed.

    any idea?

     
  7. Natty,

    This is usually a lib configuration problem. Try removing all the lib configuration and compile it again. If you get the same error, the libraries weren’t configured correctly.

     

Leave a Reply