自学内容网 自学内容网

golang 嵌入式armv7l压缩编译打包

编译 Go 应用程序

go build -ldflags="-s -w" -o myapp.exe .

使用 UPX 压缩可执行文件(window下载并设置环境变量)

upx --best --lzma myapp.exe  

可从10M压缩到1M

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

@echo off

REM Set Go environment variables

set CGO_ENABLED=0

set GOOS=linux

set GOARCH=arm

set GOARM=7

REM Compile the Go program

echo Compiling Go program...

go build -ldflags "-s -w"

REM Check if the compilation was successful

IF ERRORLEVEL 1 (

    echo Compilation failed, please check the code.

    pause

    exit /B 1

)

echo Compilation successful, packing files...

REM Use 7-Zip to package files

"C:\Program Files\7-Zip\7z.exe" a bin\tboxconfig_arm7.tar tboxconfig wwwroot config.json

IF ERRORLEVEL 1 ( 

    echo Packaging failed, please check if the folder and files exist.

    pause

    exit /B 1

)

echo Packaging successful, generated file is tboxconfig_arm7.zip

pause

exit /B 0

  


原文地址:https://blog.csdn.net/arno1988/article/details/143879017

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!