当前位置:网站首页>Clion-MinGW编译后的exe文件添加ico图标
Clion-MinGW编译后的exe文件添加ico图标
2022-07-05 20:55:00 【胡安民】
编译前准备
我们正常直接编译后生成的exe是没有任何图标的
那么很多exe程序都是有个性图标的那么在vs和qt中是比较简单的可是在Clion编译中怎么才能添加呢?
前提条件,本机必须配置好MinGW,并且环境变量也都添加了
经过自己研究发现,我们需要创建一个ico.rc文件放在项目的根目录, 然后给这个文件添加一些配置信息
id ICON "logo.ico" //添加图标
#include <winver.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,10
PRODUCTVERSION 1,0,0,10
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080404b0" //支持中文
BEGIN
VALUE "CompanyName", "***有限公司\0"
VALUE "FileDescription", "软件名称\0"
VALUE "FileVersion", "1.0.0.10\0"
VALUE "ProductVersion", "1.0.0.10\0"
VALUE "LegalCopyright", "版权所有 (C) ***有限公司\0"
VALUE "LegalTrademarks", "***有限公司\0"
VALUE "OriginalFilename", "version.exe\0"
VALUE "ProductName", "软件名称\0"
VALUE "InternalName", "version.exe\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x804, 1200 //语言-简体中文
END
END

1.编译ico.rc>ico.o
然后将图标命名为logo.ico 放在项目的根目录,之后我们需要将ico.rc文件编译为ico.o
windres -i "ico.rc" -o "ico.o"

然后有两种方式,手动打包exe和使用Clion编译exe ,下面图片是项目结构和主文件

2.编译为执行文件exe
手动编译
进入项目的根目录然后
gcc module/calculate/calculate.c module/str/str.c ico.o -g -o main main.c
注意: module/calculate/calculate.c module/str/str.c 这些都是 main.c的依赖文件,打包的时候都需要一起带上 ,而ico.o 需要编译进exe中才会生效
Clion编译

然后我们进行编译,就会将图标和信息都添加到exe中了
效果


想要非常好看的图标,可以使用ps自行修
详细信息乱码解决

这是啥问题呢? 这是因为windows默认的是ANSI码 ,而我们使用的是UTF-8编译的ico.rc文件
解决办法使用NotePad++ 将ico.rc文件的UTF-8编码转换为ANSI码 ,然后Ctrl+s保存
之后依据上面的教程, 将ioc.rc从新编译为ioc.o文件,然后在重新打包项目为.exe ,效果如下:

修改exe图标无效
当我们想将exe的图标换成其他的图标,发现新的图标只要和旧的图标名称一样那么,自动就会变为旧的图标,这是因为windows,ico缓存的问题
解决办法 在cmd中输入下命令就行了
taskkill /im explorer.exe /f
cd /d %userprofile%\appdata\local
del iconcache.db /a
start explorer.exe
exit


边栏推荐
- Redis唯一ID生成器的实现
- Duchefa丨P1001植物琼脂中英文说明书
- 研學旅遊實踐教育的開展助力文旅產業發展
- Is it necessary for bazel to learn
- Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
- Clear app data and get Icon
- 示波器探头对测量带宽的影响
- Careercup its 1.8 serial shift includes problems
- Norgen AAV提取剂盒说明书(含特色)
- 从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
猜你喜欢

Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel

基于flask写一个接口

Duchefa丨S0188盐酸大观霉素五水合物中英文说明书

解读协作型机器人的日常应用功能

Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing

Abnova total RNA Purification Kit for cultured cells Chinese and English instructions

Duchefa丨D5124 MD5A 培养基中英文说明书

Abbkine trakine F-actin Staining Kit (green fluorescence) scheme

Duchefa丨MS培养基含维生素说明书

Open source SPL eliminates tens of thousands of database intermediate tables
随机推荐
Norgen AAV extractant box instructions (including features)
Duchefa low melting point agarose PPC Chinese and English instructions
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Is Kai Niu 2980 useful? Is it safe to open an account
Abnova maxpab mouse derived polyclonal antibody solution
Is it necessary for bazel to learn
线程池的使用
树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
大二下个人发展小结
Duchefa p1001 plant agar Chinese and English instructions
浅聊我和一些编程语言的缘分
MYSQL IFNULL使用功能
Monorepo管理方法论和依赖安全
Clear app data and get Icon
序列联配Sequence Alignment
ts 之 类的简介、构造函数和它的this、继承、抽象类、接口
Abnova cyclosporin a monoclonal antibody and its research tools
MySQL InnoDB架构原理
基于flask写一个接口
教你自己训练的pytorch模型转caffe(三)