In Windows, using mingw's gcc, is there anyway to specify that the output exe file is to take an icon file, so that the exe file shows with that icon in explorer?
3 Answers
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 your
application, add the following boilerplate to a new .rc
file and follow the above mentioned steps.
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
BEGIN
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
END
END
Note, the langID is for U.K. English (which is the closest localisation to
Australia I could identify.) If you want U.S. "English" then change the BLOCK
line to:
BLOCK "040904E4"
and the translation line to:
VALUE "Translation", 0x409, 1252
See VERSIONINFO resource for for info.

- 8,381
- 6
- 44
- 66

- 18,183
- 8
- 41
- 48
-
12It would be great if the example showed where to insert the ICON line. – chacham15 Nov 12 '13 at 08:02
-
And... secondly.. http://stackoverflow.com/questions/1411040/how-to-add-an-icon-to-an-application-built-with-eclipse-galileo-c-and-mingw – Erik Friesen Dec 05 '13 at 16:07
-
you can also include multiple "Translations" (it's just telling Windows that this program is translated) by just appending WORD, WORD-pairs, for example: `VALUE "Translation", 0x409, 1252, 0x809, 1252` would enable both US and UK English according to http://msdn.microsoft.com/en-us/library/aa381058.aspx. This also tells you that you can include more than one 'BLOCK "lang04E4"' – WorldSEnder May 18 '14 at 14:24
-
I used Nirsoft's free utility `IconsExtract` to get an icon embedded in an `exe` that I needed. – Evgeni Sergeev Oct 22 '14 at 12:50
-
1Where do you get `windres`? I've got `binutils-mingw-w64-i686` already installed, but windres is not found. – endolith Jan 13 '23 at 18:02
In the RC file, the nameID does not even have to be a name, it can just be an integer. The filename must be quoted only if it contains a space. Instead of:
windres my.rc -O coff -o my.res
You can use:
windres my.rc my.o

- 1
- 62
- 391
- 407
-
1I couldn't link the `my.o` with MinGW's `g++` after `windres my.rc my.o` (some `WinMain`-related error message), but the `windres my.rc -O coff -o my.res` path worked fine. – Evgeni Sergeev Oct 22 '14 at 12:48
-
`.o` (= COFF automatically; I name it like `my.res.o` for clarity) works for me. Actually `.res` files as produced by MSVC have a different format, so it seems to be odd/incompatible using COFF in `.res` – kxr Nov 06 '19 at 19:46
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

- 179
- 4
-
This was way easier. Just opened the .exe, clicked "Add Binary or Image Resource", opened the .ico file, and saved. – endolith Oct 10 '19 at 19:12