How to reduce compiled file size?

前端 未结 12 737
野性不改
野性不改 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:29

    More compact hello-world example:

    package main
    
    func main() {
      print("Hello world!")
    }
    

    We are skiped large fmt package and noticeably reduced binary:

      $ go build hello.go
      $ ls -lh hello
      ... 259K ... hello2
      $ strip hello
      $ ls -lh hello
      ... 162K ... hello2
    

    Not so compact as C, but though measured in K not M :) Ok, it is not general way just shows some ways to optimize a size: use strip and try to use minimum packages. Anyway Go is not language for making tiny sized binaries.

提交回复
热议问题