2018-09-09 02:58


  • IT行业问题
  • 计算机技术
  • it技术
  • 编程语言问答
  • 互联网问答

I have a main.go file with a glide.yaml file (see below for source code) in a clean gopath (No other repositories)

Running go get -u ./... then go build main.go generates a binary of size 2377872 bytes.

Cleaning the gopath of any repos that were cloned from go get, and running glide update then go build main.go generates a binary of size 2457328 bytes.

Why are binaries of different sizes, if there was no code changes? What does go build do differently? Why does having a vendor directory (or not having one) affect this size?

Software versions used

glide version 0.13.1
go version go1.10.3 darwin/amd64


package main

import (
    log ""

func main () {
        "qqs": "q1",
    }).Info("Why are binaries different?")


- package:
  version: 1.0.6
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duangu1878 duangu1878 3年前

    go build by default includes debugging information in the executable, including the path of the source code files.

    When you have a vendor/ directory the path of the source files will be longer than when you the source files lie inside GOPATH. As a result, the debugging information will take up more space.

    Try comparing the size of the built binary by telling go build to exclude the debugging information like this.

    go build -ldflags=-s ./

    That reduces the difference in size. See for more details about the linker flags.

    (Edit: the source file paths are included when debugging information is not included as well as is evidenced by stack traces from a panic(), so this answer is not complete)

    点赞 评论 复制链接分享