当前位置:网站首页>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
边栏推荐
- 1.1、稀疏数组
- Live broadcast starrocks technology insider: low base global dictionary optimization
- Ue5 gas learning notes 1.6 skills gameplay ability
- Details of iptables firewall
- Digital torrent: resource reorganization and strategic conflict in enterprise transformation
- Is the training institution of software testing reliable
- 顿悟!百度强推的Redis天花板笔记,原来数据库是这样理解的
- What skills do you need to master when learning software testing zero foundation?
- Is it really realistic that people who have not been exposed to software testing can take up their posts after two months of training?
- Introduction to oscilloscope
猜你喜欢

Brief introduction: basic principle of srv6

【译】创意编码之噪音

UE5 GAS 学习笔记0.2配置插件

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,

Introduction to advanced design system (ads) 2009 RF simulation

ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法

Random talk on GIS data (VI) - projection coordinate system

实验楼----PHP大法

GIS数据漫谈(六)— 投影坐标系统

.net WCF WF4.5 状态机、书签与持久化
随机推荐
Ue5 gas learning notes 1.6 skills gameplay ability
Implementation of solid transfer function (based on transfer)
VMware virtual machine networking settings (win10 comes with virtual machine installation win7)
What role does low code play in the digital transformation?
Introduction to main parameters of antenna
WordPress prompt error in establishing database connection
新手记录:机械键盘的一些小知识
1.1、稀疏数组
#夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)
Docker builds MySQL master-slave replication
VSC writes go, expected 'package' appears, found 'EOF‘
Mongodb initialization operation
Novice record: some small knowledge of mechanical keyboard
.net WCF WF4.5 状态机、书签与持久化
Summer Challenge [FFH] JS custom component: DIY a keyboard that can be used at any time! (I)
What is the employment prospect of software testing?
Mysql操作大全
Ue5 gas learning notes 1.2 game Tags
Seven steps, in-depth interpretation of data meaning
Introduction to the principle of signal source