当前位置:网站首页>GO exe生成图标版本信息
GO exe生成图标版本信息
2022-07-28 17:04:00 【谱写】
为什么要添加图标和详细信息
作为桌面程序,有一个图标,显得更正式一些。详细信息有版本号方便做版本识别。算了,编不下去了。不管那么多,反正别人有这些,你就应该有这些功能(无奈)。golang 作为一个后端语言,对windows 界面编程支持不是那么友好,直接添加图标和详细信息有一定难度。还好有第三方库–GoVersionInfo,可以帮助我们解决这一难题。
GoVersionInfo是用于Go语言的Microsoft Windows文件属性/版本信息和图标资源生成器
程序包将创建一个syso文件,其中包含Microsoft Windows版本信息和一个可选图标。当您运行“ go build”时,Go将在可执行文件中嵌入版本信息以及可选图标和可选清单。如果它与main()函数位于同一目录中,则Go将自动使用syso文件。
安装GoVersionInfo
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo将刚下载下来的GoVersionInfo 的目录github.com\josephspurrier\goversioninfo\testdata\resource拷贝到我们的工程目录(main.go所在目录).并把目录中的versioninfo.json拷贝到与main.go同目录。
修改文件
在main.go 的第一行添加:
main.go 添加注释
//go:generate goversioninfo -icon=jiuwei.ico -manifest=main.exe.manifest然后修改与main.go同一级目录下的versioninfo.json文件。将里面的字段“ProductVersion”更改为你想要的版本号即可.(同时也可以修改其他信息如:版权,产品名称,文件说明等)
{
"FixedFileInfo": {
"FileVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"ProductVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"FileFlagsMask": "3f",
"FileFlags ": "00",
"FileOS": "040004",
"FileType": "01",
"FileSubType": "00"
},
"StringFileInfo": {
"Comments": "Test file.",
"CompanyName": "Test",
"FileDescription": "Test",
"FileVersion": "v1.0.0.0",
"InternalName": "Test.exe",
"LegalCopyright": " 版权所有 ",
"LegalTrademarks": "",
"OriginalFilename": "Test.exe",
"PrivateBuild": "",
"ProductName": "Test",
"ProductVersion": "v1.0.0.0",
"SpecialBuild": ""
},
"VarFileInfo": {
"Translation": {
"LangID": "0409",
"CharsetID": "04B0"
}
},
"IconPath": "",
"ManifestPath": ""
}首先用,go generate 命令生成resource.syso资源文件
再用,go build 命令生成EXE文件。这里需要用Directory的方式编译,不能用File的方式编译。(也就是不能用go build main.go 这种方式)。原因是通过Directory的方式编译,编译器会自动寻找同目录下的资源文件并打包进EXE。
在编译过程中,你可能会遇到报错
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `C:\Users\hjd\AppData\Local\Temp\go-link-681106599\000000.o' is incompatible with i386:x86-64 output
collect2.exe: error: ld returned 1 exit status
上面的解决办法是,编译时带一下参数
-ldflags="-linkmode internal"
go build -o myapp.exe -ldflags="-linkmode internal" -ldflags="-H windowsgui"
go build -o ./myapp.exe -ldflags="-linkmode internal" -ldflags="-H windowsgui"
我之所以有 -ldflags="-H windowsgui" 是取消黑窗口 因为是GUI界面
边栏推荐
- 华为中兴在英国败诉,不交专利授权费将被禁售!
- The required error of solidity is reported
- 苹果供应商JDI拟以6.75亿美元出售白山LCD工厂和设备
- Video Number Xiaobai starting operation guide
- solidity转账函数的实现(基于transfer)
- Import the database backup of MySQL 8 into MySQL 5
- 明德生物:公司暂未有产品被列入WHO推荐清单
- cout.write的学习
- Live broadcast starrocks technology insider: low base global dictionary optimization
- Mqtt over quic: the next generation Internet of things standard protocol injects new impetus into the message transmission scenario
猜你喜欢

Performance parameters of spectrum analyzer

Introduction to USB type-C PD fast charging

“云战略”将成为企业数字化转型的重要支柱

The growth path of hardware engineers (0) -- Understanding components

Application of Internet of things in smart city

腾讯汤道生:开源是产业互联网时代新的生产方式和协作模式

Centos8 uses docker to install WordPress in wordpress+mysql configuration file_ DB_ Understanding of host

Introduction to the principle of signal source

网络RJ45接口详解

低码在数字化转型中扮演什么角色?
随机推荐
Categories with good sales volume on the video Number
明德生物:公司暂未有产品被列入WHO推荐清单
solidity的msg.value
insight! Baidu pushed redis ceiling notes, which was originally understood by the database
ADS仿真 之 交流仿真和S参数仿真示例
苹果供应商JDI拟以6.75亿美元出售白山LCD工厂和设备
Shenzhen offline registration starrocks on AWS: how to conduct rapid unified analysis of real-time data warehouses
Principle, classification and requirements of antenna
Detailed explanation of oscilloscope probe
Cloud container and cloud native
Brief introduction: basic principle of srv6
网络RJ45接口详解
Mongodb initialization operation
Go's sleep
iptables 配置
长江存储推出自有存储品牌“致钛”,首款SSD产品曝光
欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务
Calibration of vector network analyzer (vector network)
Mingde biology: no products of the company have been listed in the WHO recommended list
Members who have opened a website need to download e-book messages for free