GO完全静态编译 您所在的位置:网站首页 cgo静态编译死机 GO完全静态编译

GO完全静态编译

2023-07-03 02:38| 来源: 网络整理| 查看: 265

1 CGO_ENABLED=0 go build --ldflags "-extldflags -static" -o bin/frps-static ./cmd/frps

实际可以看到效果如下:

1 2 3 4 5 6 7 /go/src/github.com/fatedier/frp # go build --ldflags "-extldflags -static" -o bin/frps-static ./cmd/frps /go/src/github.com/fatedier/frp # ldd bin/frps-static /lib/ld-musl-x86_64.so.1 (0x7fb254e7f000) libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fb254e7f000) /go/src/github.com/fatedier/frp # CGO_ENABLED=0 go build --ldflags "-extldflags -static" -o bin/frps-static ./cmd/frps /go/src/github.com/fatedier/frp # ldd bin/frps-static ldd: bin/frps-static: Not a valid dynamic program

bin/frps-static 就是静态的文件,再不也不是动态的了。

参考链接:

https://www.yryz.net/post/golang-docker-alpine-start-panic.html http://blog.wrouesnel.com/articles/Totally%20static%20Go%20builds/ http://blog.cloud66.com/how-to-create-the-smallest-possible-docker-image-for-your-golang-application/


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有