当前位置:网站首页>Go exe generates icon version information
Go exe generates icon version information
2022-07-28 18:40:00 【Compose】
Why add icons and details
As a desktop program , There is an icon , Be more formal . The detailed information has a version number to facilitate version identification . Forget it , I can't make it up . No matter how much , Anyway, others have these , You should have these functions ( but ).golang As a back-end language , Yes windows Interface programming support is not so friendly , It is difficult to add icons and details directly . Fortunately, there is a third-party library –GoVersionInfo, It can help us solve this problem .
GoVersionInfo Is used for Go Linguistic Microsoft Windows File attribute / Version information and icon resource generator
The package will create a syso file , It includes Microsoft Windows Version information and an optional icon . When you run “ go build” when ,Go Version information as well as optional icons and optional lists will be embedded in the executable . If it's with main() Functions are located in the same directory , be Go Will be used automatically syso file .
install GoVersionInfo
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo Download the just downloaded GoVersionInfo The catalog of github.com\josephspurrier\goversioninfo\testdata\resource Copy to our project directory (main.go In the directory ). And put versioninfo.json Copy to and main.go Same as catalog .
Modify file
stay main.go Add... To the first line of :
main.go Add notes
//go:generate goversioninfo -icon=jiuwei.ico -manifest=main.exe.manifestThen modify and main.go Under the same level of directory versioninfo.json file . Put the fields inside “ProductVersion” Change to the version number you want .( You can also modify other information, such as : Copyright , The product name , Document description, etc )
{
"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": " copyright ",
"LegalTrademarks": "",
"OriginalFilename": "Test.exe",
"PrivateBuild": "",
"ProductName": "Test",
"ProductVersion": "v1.0.0.0",
"SpecialBuild": ""
},
"VarFileInfo": {
"Translation": {
"LangID": "0409",
"CharsetID": "04B0"
}
},
"IconPath": "",
"ManifestPath": ""
}First use ,go generate Command to generate resource.syso Resource file
Reuse ,go build Command to generate EXE file . You need to use Directory The way to compile , Out-of-service File The way to compile .( That is to say, it can't be used go build main.go This way, ). The reason is through Directory The way to compile , The compiler will automatically find the resource files in the same directory and package them into EXE.
During the compilation process , You may encounter errors
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
The above solution is , Compile with parameters
-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"
The reason why I have -ldflags="-H windowsgui" Is to cancel the black window the reason being that GUI Interface
边栏推荐
- Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
- VSC上写Go出现expected ‘package‘, found ‘EOF‘
- Msg.value of solidity
- 微信公众号授权登录后报redirect_uri参数错误的问题
- 顿悟!百度强推的Redis天花板笔记,原来数据库是这样理解的
- UE5 GAS 学习笔记 1.6 技能Gameplay Ability
- Introduction to oscilloscope
- Ue5 gas learning notes 1.10 prediction
- UE5 GAS 学习笔记0.2配置插件
- Summary of core knowledge points of Computer Composition Principles & key points of written interview [easy to understand]
猜你喜欢

【译】创意编码之噪音

微信公众号授权登录后报redirect_uri参数错误的问题

NDK 系列(5):JNI 从入门到实践,爆肝万字详解!

Composition and principle of vector network analyzer (vector network)

SQL Server stuff and for XML path

1.2、队列

深圳线下报名|StarRocks on AWS:如何对实时数仓进行极速统一分析

Noise of creative coding

It is said that software testing is the worst in the IT industry. Is that so?

LeetCode_63_不同路径Ⅱ
随机推荐
Tencent Tang Daosheng: open source is a new mode of production and collaboration in the era of industrial Internet
Digital torrent: resource reorganization and strategic conflict in enterprise transformation
顿悟!百度强推的Redis天花板笔记,原来数据库是这样理解的
Brief introduction to the principle of spectrometer II
GO exe生成图标版本信息
Noise of creative coding
NPM cannot recognize the "NPM" item as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is correct,
MongoDB创建索引
MongoDB数据库复制表
UE5 GAS 学习笔记 1.10 预测(Prediction)
What is the employment prospect of software testing?
iptables 配置
直播|StarRocks 技术内幕 :低基数全局字典优化
Go语言系列之日志库zap
408复习策略(强化阶段)
一文简述:SRv6基本原理
Mqtt over quic: the next generation Internet of things standard protocol injects new impetus into the message transmission scenario
1.3、链表
LeetCode79题 方法一:深度搜索
Summer Challenge [FFH] JS custom component: DIY a keyboard that can be used at any time! (I)