How to reduce compiled file size?

前端 未结 12 755
野性不改
野性不改 2020-11-28 20:59

Lets compare c and go: Hello_world.c :

#include
int main(){
    printf(\"Hello world!\");
}

Hello_world.go:

         


        
12条回答
  •  庸人自扰
    2020-11-28 21:32

    The 2016 answer:

    1. Use Go 1.7

    2. Compile with go build -ldflags "-s -w"

    ➜ ls -lh hello
    -rwxr-xr-x 1 oneofone oneofone 976K May 26 20:49 hello*
    

    3. Then use upx, goupx is no longer needed since 1.6.

    ➜ ls -lh hello
    -rwxr-xr-x 1 oneofone oneofone 367K May 26 20:49 hello*
    

提交回复
热议问题