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:
- Download and install MinGW if you don’t already have it. Add MinGW’s
binsubdirectory to yourPATHenvironment variable. Note that if you use Vista, you must override GCC’s utilities with their corresponding Vista builds; - Download and install MSYS - you will need it to compile wxWidgets. Add its bin subdirectory to
PATHas you did with MinGW; - Open the MSYS console and navigate to the directory where you extracted wxWidgets (or where the installation put the files from wxWidgets);
- Create a directory for your build (
mkdir build-static-debug) and navigate to it. You may want to use other names; - 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 - Run
maketo 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; - Remove object files with
rm *.o(you’re not going to need them); - Run
make installto 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:
- First of all, make sure NetBeans recognizes your MinGW + MSYS setup. Go to
Tools --> Options, then selectC/C++. Check if MinGW and MSYS bin subdirectories are listed on the current path list. Add them if they aren’t.makeshould be found inside MSYS whilegcc,g++andgdbshould be found inside MinGW; - Now that NetBeans recognizes your MinGW + MSYS setup, it’s time to create a new wxWidgets project. Go to
File --> New Project...and selectC/C++ application; - With your project open, enter the project properties dialog;
- Select
C/C++ --> C++ Compiler --> General options; - Open the MSYS console and navigate to the directory where you’ve made your wxWidgets build (e.g.
build-static-debug) and enterwx-config --cxxflags.wx-configwill output the compiler flags for your project. On my machinewx-config --cxxflagsoutputs-I/c/wxWidgets-2.8.7/msw-debug/lib/wx/include/msw-uni. Remember to leave this console open;
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 - Add all directories preppended with
-Ifromwx-configoutput to the include directories of your project; - Select
Command lineand put the remaining flags fromwx-configthere; - Now select
Linker --> General options; - Back on the MSYS console, type
wx-config --libs.wx-configwill output the linker flags for your project. On my machinewx-config --libsoutputs-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; - Add the directory preppended with
-Lto theAdditional library directoriesinsideGeneral optionsand click OK to close this dialog; - Now select
Linker --> Libraries --> Add option... --> Other option...; - Back on the MSYS console, copy the remaining linker flags;
- Paste the remaining flags from
wx-config --libson 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!; - 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.
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
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.
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.
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…
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.
I did everything exactly as explained, but I keep getting undefined references … and then the build is failed.
any idea?
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.
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.