How do I add an icon to a mingw-gcc compiled executable? How do I add an icon to a mingw-gcc compiled executable? windows windows

How do I add an icon to a mingw-gcc compiled executable?


You need to create the icon first. Then you need to create a RC file with the below content. Here we'll name it as my.rc.

id ICON "path/to/my.ico"

The id mentioned in the above command can be pretty much anything. It doesn't matter unless you want to refer to it in your code. Then run windres as follows:

windres my.rc -O coff -o my.res

Then while building the executable, along with other object files and resource files, include my.res which we got from the above step. e.g.:

g++ -o my_app obj1.o obj2.o res1.res my.res

And that should be all there is to it.


And, at no extra charge, if you want to include version information in yourapplication, add the following boilerplate to a new .rc file and follow the above mentioned steps.

1 VERSIONINFOFILEVERSION     1,0,0,0PRODUCTVERSION  1,0,0,0BEGIN  BLOCK "StringFileInfo"  BEGIN    BLOCK "080904E4"    BEGIN      VALUE "CompanyName", "My Company Name"      VALUE "FileDescription", "My excellent application"      VALUE "FileVersion", "1.0"      VALUE "InternalName", "my_app"      VALUE "LegalCopyright", "My Name"      VALUE "OriginalFilename", "my_app.exe"      VALUE "ProductName", "My App"      VALUE "ProductVersion", "1.0"    END  END  BLOCK "VarFileInfo"  BEGIN    VALUE "Translation", 0x809, 1252  ENDEND

Note, the langID is for U.K. English (which is the closest localisation toAustralia I could identify.) If you want U.S. "English" then change the BLOCKline to:

BLOCK "040904E4"

and the translation line to:

VALUE "Translation", 0x409, 1252

See VERSIONINFO resource for for info.


In the RC file, the nameID does not even have to be a name, it can just bean integer. The filename must be quoted only if it contains a space. Insteadof:

windres my.rc -O coff -o my.res

You can use:

windres my.rc my.o


Try Resource Hacker. I was able to cross compile my project in Linux (WSL) and generate an icon from the logo on the homepage. Just needed a simple way to embed it in the exe and this program worked great.Resource Hacker by Angus Johnson