Use Resource files with Eclipse and wxWidgets

While developing with Eclipse  C++ CDT and wxWidgets & MinGW I run along an issue. In Windows wxWidgets requires an MS resource (.rc) file to be compiled along with the project. The file contains the location to the application icon along with an include to the wx resource file. One issue I came across when compiling without including the Resource file to the binary was the rendering of the toolbar. The application would render the toolbar in Windows 95 style.

The resource file content looks like the following:

aaaa ICON "wx/msw/std.ico"

#include "wx/msw/wx.rc"

In order to include the resource file in the binary you first have to use Windres (Windres should be in the PATH system variable as a part of the MinGW suite) through the command prompt:

windres --use-temp-file -isample.rc -osample_rc.o -Iincludepath

You have to replace includepath with the path to the wxWidgets header folder (parent of the wx folder which contains the msw folder).

After you successfully compile the resource file you have to go to Eclipse, right click on the project and open Properties. Once there go to C/C++ Build, and then choose Settings, then go to MinGW C++ linker, and select Miscellaneous. Then go to Other Objects and add the sample_rc.o file. After this you are done and the sample_rc.o should be part of the binary. If you kept the default wxWidgets Resource file, like above you should see the application icon being the default wxWidgets Icon. Also the toolbar should have the proper style, and not the Windows 95 one.