www.rodneybeede.com "I would love to change the world, but they won't give me the source code" - unknown

Compiling a C++ Windows executable with a custom icon - Last Modified 2008-10-07 17:53 UTC - Created 2008-10-07 17:53 UTC

This example shows how to compile a simple C++ program into a standalone Windows executable (32-bit) with a custom icon.

I used MinGW version 3.15.1 with GCC 3.4.5.

  1. Start by creating a test.cpp example file
    using namespace std;
    int main () {
     cout << "Hello World!";
     return 0;
  2. Create a resource file (say appicon.rc) with a line defining the location of your .ico file
    AppIcon ICON "MyApp.ico"
  3. Compile the icon into a resource object with a command like
    C:\MinGW\bin\windres.exe appicon.rc appicon.opc
  4. Compile your executable with the resource object included with a command like
    "C:\MinGW\bin\g++.exe" appicon.opc test.cpp