為Go編譯的Windows程式加入資源檔案

2022-09-11 04:21:13 字數 490 閱讀 4775

首先編寫乙個rc檔案,如main.rc,內容如下:

idi_icon1 icon "

icon.ico"1

24"main.exe.manifest

"

icon指的是程式的圖示,下邊的manifest是讓程式使用windows主題,string table 、version等按照普通rc檔案寫入即可。

windres -o main-res.syso main.rc

go build -ldflags '

-h windowsgui -w

'

這樣生成的exe就有了圖示,並且應用了windows的主題。

其中ldflags中的引數,"-h windowsgui"為隱藏命令列視窗,因為我寫的是gui程式,"-w"是裁剪gdb除錯資訊,這樣生成的exe體積會小一些。

windres.zip

go_res.zip

Windows下交叉編譯Go

編譯為linux可執行檔案 set cgo enabled 0 set goos linux set goarch amd64 go build main.go編譯為mac可執行檔案 set cgo enabled 0 set goos darwin set goarch amd64 go buil...

windows 編譯 python指令碼為exe檔案

安裝 c python27 scripts cxfreeze.bat python路徑要修改對 在需要編譯的 py 檔案同資料夾新建乙個 setup.py 為 usr bin env python from cx freeze import setup,executable setup name h...

Go 專案編譯Linux或Windows可執行檔案

set cgo enabled 1set goarch set goos windows go buildset cgo enabled 0set goarch amd64 set goos linux go build上述打包只能打包go語言檔案,如果專案中使用了靜態資源或配置檔案不會被進行打包,...