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 by 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.

18 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.

     
  8. thanx for this tutorial! Great work. Just one remark. Executing wx-config I got pathnames without /c/. So I have just to prepend the wxWidgets installation path before copying the path into the netbeans configuration.

     
  9. Oi achei o linker, atende pelo nome e vinculador. Essas versoes traduziadas de IDE é um horror, como voce ainda nao autorizou o post anterior, pode excluir.

    So uma pergunta como habilitou o wxWidgets para mostrar acentos?

     
  10. Maiko,

    To use accents directly in your code you have to make sure that:

    1. Your wxWidgets build supports unicode. Check the 5th step of the first part of the tutorial for more info;
    2. You are using the _T or wxT macros. It is a good practice to always use one of these macros whenever you use literal strings because even if you use an ASCII only build, these macros will simply return the value you’ve passed;
    3. You are using unicode codes for every non ASCII character. For example: instead of using "Ação", you must use _T("A\u00E7\u00E3o").
     
  11. Thank you for writing this out! This is the only description I could find anywhere that actually showed how to set up wxWidgets *after* doing the installation.

    Comments:

    First, I am building the Hello World example, nothing custom or special.

    – “configure” fails unless I set –host i386-mingw (miracle I figured this out — this option I could not find documented anywhere, even in ‘configure –help’).

    – Easier than typing the wx-configure line, I added this to the compiler options:

    `{full-path}/wx-config –cxxflags`

    Note that these are backticks and NOT single quotes. This executes the command on the fly and is less error prone I feel. Similar option for linker is possible.

    – step 13 is the breaking point. I did everything you said in every possible combination but I still get the ugly linker errors. I must need different options during configure, but what? Too many choices.

    My setup: Windows 7 on intel i3, NetBeans 6.9, wxWidgets 2.8.11, MinGW 5.1.6, MSys 1.0.11 (I don’t think this is the latest version, but the newer versions don’t seem to include ‘make’ and NetBeans won’t work with MinGW’s make).

     
  12. A few updates to the last comment:

    – I redid the “configure” and enabled many more options. I also tried many more –host choices and settled on i686-mingw32

    – In NetBeans, the `wx-config –libs` can only go into one place:

    In Project, choose properties. Then, go to the linker section. Find the “Libraries” line and expand the “…” button. Click “Add Option” then choose the “Other Option” button. Enter `wx-config –libs` here.

    After several days, ‘hello world’ compiles and links. These are all good systems but there so many options and platforms, that a detailed description needs to be written for each different setup. The general purpose setups suffer because of the lack of documentation. I thank you again for this best tutorial and am happy to contribute my own writing if wanted.

     
  13. @ Ben Jenkins
    Thank you very much for your last comment, I was stuck for an hour trying to figure out, why my netbeans configuration wouldn’t work.

    @ Dalton
    A big thank you goes out to you too, for writing this tutorial in the first place!

     
  14. Hey there =)
    I’m following this tutorial, but i can’t get past this line “/configure –enable-debug –disable-shared –enable-unicode”
    i read the comments on this, and i set the host as Ben said, but still, i get the configure command not found…any ideas? u.u
    i’ve tried ruunning wxwidgets on java, but no luck so far, so i’m trying c++….i really need to work this out, i’d really thank you if you could help me! ; ;

     
  15. Thanks very much Dalton for this very very useful tutorial.
    One million thanks to Ben Jenkins for the right placement of ‘wx-config –libs”

    Paolo

     
  16. I am stuck a step 7: Select ‘Command line’ and put the remaining flags from wx-config there.

    I am using NetBeans 7.1.1 and when I am in the Project Properties, there is no ‘Command line’ tab or anything.

     
  17. Found the answer to my previous problem. It has been renamed “Compilation Line”.

    Also, I initially had a problem during compilation that produced the following error on Netbeans:
    make: *** [build/Debug/MinGW-Windows/main.o] Error 1
    BUILD FAILED (exit value 2, total time: 566ms)

    However, after looking through setup instruction at Netbeans, I found that it is important to install MSYS using “Administrator Privileges” on Windows. I also used the MSYS provided through the direct link.

    The aforementioned setup instruction is at:
    http://netbeans.org/community/releases/71/cpp-setup-instructions.html

    Hope this helps!

     
  18. hi dalton

    can u tell me how to do the same using netbeans 7.1.1 using wxwidgets 2.9.3 .

    thanks

     

Leave a Reply