duanli9930 2016-02-24 08:01
浏览 14

前往:编译时可以控制静态或动态库链接吗? 每个都创建差异。 二进制大小?

In one of the Go seminars, the lecturer said that when he compiled the Go application, statically linked, the size of the resulting binary was about 600 MB big, but when he compiled the same app with static linking, the resulting binary turned into 10 MB.

I'm not sure what he is talking about, can dynamic vs. static linking during compilation make that difference in space of binary, and do I have control over that?

  • 写回答

1条回答 默认 最新

  • doulan4371 2016-02-24 08:32
    关注

    By default Go uses static linking so everything (your code and packages sources) compiles in one big binary.

    Since Go 1.5 released you can compile Go shared library using -buildmode=shared option for go build or go install. Then you can compile your app binary with -linkshared flag. Details can be found here.

    Ofcourse, if you link packages dynamically your binary size will be less than with static linking, but total application size will not be reduced because you just "put your code in other place". So dynamic linking makes sense only if you need to share the same packages between different apps.

    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题