如何将图标添加到mingw-gcc编译的可执行文件?
在Windows中,使用mingw的gcc,有没有办法指定输出exe文件是否需要一个图标文件,以便exe文件在explorer中与该图标一起显示?
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?
您需要先创建图标。然后你需要创建一个RC文件,
看起来像这样:
You need to create the icon first. Then you need to create a RC file that looks something like this:
id ICON "path/to/my.ico"
ID几乎可以做任何事情。除非你想在代码中引用
,否则这并不重要。然后运行windres,如下所示:
The ID can 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
然后,您只需在链接时将my.res与您的目标文件一起包含,例如:
Then you just include my.res along with your object files when you link, e.g.:
g++ -o my_app obj1.o obj2.o my.res
这应该就是它的全部。
而且,如果您不收取额外费用想要在您的
应用程序中包含版本信息,请将以下样板文件添加到 .rc
文件并适当修改
:
And, at no extra charge, if you want to include version information in your
application, add the following boilerplate to your .rc
file and modify
appropriately:
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
请注意,langID适用于英国英语(这是与我可以识别的
澳大利亚最接近的本地化版本。)如果您需要美国英语,请更改 BLOCK
行至:
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
请参阅 VERSIONINFO资源供参考。