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
bin
subdirectory to yourPATH
environment 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
PATH
as 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
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; - Remove object files with
rm *.o
(you’re not going to need them); - 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:
- 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.make
should be found inside MSYS whilegcc
,g++
andgdb
should 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-config
will output the compiler flags for your project. On my machinewx-config --cxxflags
outputs-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
-I
fromwx-config
output to the include directories of your project; - Select
Command line
and put the remaining flags fromwx-config
there; - Now select
Linker --> General options
; - Back on the MSYS console, type
wx-config --libs
.wx-config
will output the linker flags for your project. On my machinewx-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
; - Add the directory preppended with
-L
to theAdditional library directories
insideGeneral options
and 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 --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!; - 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.
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?
Maiko,
To use accents directly in your code you have to make sure that:
_T
orwxT
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;"Ação"
, you must use_T("A\u00E7\u00E3o")
.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).
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.
@ 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!
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! ; ;
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
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.
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!
hi dalton
can u tell me how to do the same using netbeans 7.1.1 using wxwidgets 2.9.3 .
thanks