Compiling a C++ Windows executable with a custom icon

Last Modified: Tue, 07 Oct 2008 17:53:00 +0000 ; Created: Tue, 07 Oct 2008 17:53:00 +0000

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
    #include 
    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