I want to add icon to exe file of my application? How can I do it. I would like it's added automatically when I build my app with dub.
Asked
Active
Viewed 566 times
3
-
3http://forum.dlang.org/thread/wogdypudrmrgwjysfkxg@forum.dlang.org#post-mailman.8.1363202377.4724.digitalmars-d-learn:40puremagic.com see this tutorial – Cui Heng Feb 12 '15 at 14:48
-
I would like to do it's with dub... – Suliman Feb 12 '15 at 15:07
-
I don't know much about dub but from the docs maybe a `preBuildCommand` to call the resource compiler (`rcc` see the link above) and a `sourceFiles-windows` listing the `.res` file (generated by the resource compiler) will do what you need. – Adam D. Ruppe Feb 12 '15 at 19:33
1 Answers
4
I guess I'll write up my comment as an answer as it is the closest we have.
To add an icon to the application, you first make a resource file, add the icon, then compile that resource into the exe. I explained how to do this in an old thread here and there's a wiki page linked too: http://forum.dlang.org/post/mailman.8.1363202377.4724.digitalmars-d-learn@puremagic.com
To achieve this with dub, I'd try adding a preBuildCommand
to compile the resource to your dub configuration file, then add a sourceFiles-windows
argument for your compiled resource. If the resource is added to dmd as a source file, it will know what to do and pass it to the linker.

Vladimir Panteleev
- 24,651
- 6
- 70
- 114

Adam D. Ruppe
- 25,382
- 4
- 41
- 60
-
I know this was 3 years ago, but I am getting an error that I don't understand. `icon.rc(1) : Error: 'icon.ico' doesn't contain a valid Windows 3.0 icon resource` I made the icon in PNG format, sized it down to 16, 32, 64, 128, 256, and used `magick convert` to create an icon file out of them. This should be a valid icon. – Jacob Birkett Jun 27 '18 at 05:12
-
you doing a 32 or 64 bit build? it might be that the file version isn't 32 bit compatible (the D tools that come with it are super old, whereas the 64 bit will use Microsoft's). also the ico file should display in the windows shell as the image itself, if it doesn't, the format may legit be wrong – Adam D. Ruppe Jun 27 '18 at 13:35
-
I'm not sure. I didn't use the `-32` flag if that's what you're asking. The icon should work fine, I have used icons generated this way with other applications. This is the icon I am trying to use: https://tknk.io/lA4h – Jacob Birkett Jun 27 '18 at 18:22
-
IS there a way to programmatically add the icon to the executable without using this resource file? If I could write a small script to run after compiling the executable that would add the icon I think that would be easier. How does Resource Hacker do it? – Jacob Birkett Jun 27 '18 at 18:24
-
You can just use Resource Hacker itself to do it. But yeah the file looks ok, I think it is just that ancient rcc.exe doesn't like the 256x256 png icon. If you remove that entry, then the old rcc.exe will compile it successfully and add the icon. So that's one option, or use Resource Hacker to add after-the-fact, or use Microsoft's own `rc.exe` program instead (or Visual Studio has it built in btw) to compile the resource then link it in. – Adam D. Ruppe Jun 27 '18 at 22:40