golang打包windows可执行程序
golang下给windows的可执行文件进行打包
-
下载MinGW
- MinGW is a compiler system uses GCC to produce Windows programs. Win32 ports of GCC, GDB, binutils to build native Win32 programs that rely on no 3rd party DLLs.
-
安装完成后,下载gcc的包
-
Install GCC
Install GCC (GNU C Compiler) from MinGW, select mingw32-gcc package from All Packages → MinGW → MinGW Based System in left sidebar, and click Apply change in Installation menu.
-
-
检验gcc是否可以用,在命令行下运行gcc -v看看有没有输出
-
安装完成后,将MinGW的路径和MinGW\bind的路径加入系统的Path中
-
创建一个文件夹出来,将main.go以及对应的go文件放在一起
-
下载一个icon文件,起名为main.ico也放在一起
-
创建main.rc文件
IDI_ICON1 ICON "main.ico"
1 24 "main.exe.manifest"
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGS 0x0L
FILEFLAGSMASK 0x3fL
FILESUBTYPE 0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "FileDescription", "阿弥陀佛"
VALUE "FileVersion", "1.0"
VALUE "LegalCopyright", "Mark"
VALUE "InternalName", "去试试吧"
VALUE "OriginalFilename", "amituofo"
VALUE "ProductName", "念经吧"
VALUE "ProductVersion", "1.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END
- 创建main.exe.manifest文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="x86"
name="controls"
type="win32"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
- 在该文件夹下运行下面的命令
windres -o main-res.syso main.rc && go build -i
就会生成一个以该文件夹名为命名的exe文件,带有对应的icon和编辑的属性信息