Feb 20, 2014

Using WxWidgets 3.0 in Microsoft Visual Studio 2012 or 2013

For the past year I've been caught in experiment, now would swing back to the simulation side. For some reasons, I want to develop a program with a easy-to-use UI. For present, I would use it for my study; for near future, it might be helpful for new comers in this field. After a brief searching on the Qt or WxWidgets, I simply pick up WxWidgets.

The problem is how to use it with Microsoft Visual Studio (2012 or 2013 at present). I went through a tough way in configuring FFTW before(basically it is using DLL in visual studio), so this time  I try to find a way as easy as possible that people like me who is not coder but have to code could follow.

And here it is.


  1. Install the  Microsoft Visual Studio 2013 (any edition works for you, or 2012), just click and go.

    2. Download and install the WxWidgets 3.0.0. (present it's Version 3.0.0 and windows installer edition is recommended). As recommended in the documentation, install it without space in the path name, so I simply use the default: "C:\wxWidgets-3.0.0".

    3.  Open the Advanced System Settings(see screenshot) and click on the "Environment Variables...".
















    4. Add a New item: Variable name: WXWIN, Variable value: C:\wxWidgets-3.0.0 (path of your wxwidgets);


     5.  Go to your wxWidgets folder (here, for example, C:\wxWidgets-3.0.0), open the "\build\msw\wx_vc10.sln" file with visual studio (just double click on it).  If prompted with some update of the files, just hit "OK". 

    6.  Build this solution (hit F7 or from menu) for "Debug" and "Release" separately(choose the build type as shown in the picture, each build process needs may be 1~2 min). (Note: If you need DLL, just build the DLL Debug and DLL Release). It should build without error and show something like"========== Build: 23 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========".


     7.   Now go to your wxWidgets folder and open "\samples\minimal\minimal.dsw" with visual studio (double click only). Again,  if prompted with some update of the files, just hit "OK". Then build it (hit F7, or F5 for debug mode) for debug or release to test it works OK or not. It should build without error pretty quickly and now you have a new folder called "vc_mswud" under "\samples\minimal\vc_mswud", where you would find a setup called "minimal.exe".
     8.  Double click it to see this setup.

     9. When you close the Visual Studio, it will ask you to save the change or not, just click Yes and save it to the same folder. As shown here.


     10.  Done. Now you can just develop your own code by modify this "minimal" example. But usually, you might want your project in other places, for example, I'd like my project in my Documents folder and there's too many files in present folder. We could copy only those we need to start a new project. After Step 7-9, you may notice that there are several new files generated in the "minimal" folder, among them: minimal.vcxproj, minimal.sln. What we need to copy are these two files and minimal.cpp(or you can write you own .cpp file). 

     11. Open the .vcxproj with notepad and replace ".\..\.." with  "C:\wxWidgets-3.0.0" (where you install your wxWidgets). In my case, I got 28 places replaced. 


     12.  then open the .vcxproj file with Visual Studio (double click only), and delete the sample.rc file (because we don't have it anymore)
     13.  Hit F5 for debug mode or F7 for build mode and you should see no problem with it. Now you can start you own project now. EXTRA: if you want to change the project name(for example, MyApp), please be sure that you do it this way:
a. change file name: minimal.vcxproj -> MyApp.vcxproj, minimal.sln ->MyApp.sln, minimal.cpp->MyApp.cpp
b. open .vcxproj file with notepad and replace all "minimal" with "MyApp"
c. open .sln file with notepad and replace all "minimal" with "MyApp"

Brief Summary:
With all these mentioned above, the idea is rather simple: After install the WxWidgets, we run the wx_vc10.sln to have it build the necessary library for us, then we can build the sample which is in the "workspace" of wxWidget. If we want to our own project on a different place(workspace), we have to configure the settings to connect to the library, which is saved in the vcxproj file. So we just simply change the path in it to avoid configuring from the scratch. 

The above method is derived from various resources, among which the most useful comes from wxWidgets's wiki page,which is little bit out-of-date though.