duanshaiduhao2471 2013-12-04 07:03
浏览 143
已采纳

gccgo -static与-static-libgo

What is the difference between -static and -static-libgo for gccgo? The documentation doesn't seem to really shed light on what is going on:

  • Use the -static-libgo option to link statically against the compiled packages.
  • Use the -static option to do a fully static link (the default for the gc compiler).

Is -static-libgo only static linking libgo.a only? While -static is full glibc library?

  • 写回答

1条回答 默认 最新

  • douhuangjie4503 2014-02-25 10:40
    关注

    Check the dynamic linkage in the generated ELFs:

    gc builds statically:

    $ go build hello.go
    $ readelf -d hello
    There is no dynamic section in this file.
    

    gccgo links dynamically against libgo, libc etc. by default:

    $ go build -compiler gccgo hello.go
    $ readelf -d hello
    Dynamic section at offset 0x36e0 contains 29 entries:
      Tag        Type                         Name/Value
     0x0000000000000001 (NEEDED)             Shared library: [libgo.so.5]
     0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
     0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
     0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
    

    Bake libgo inside the executable, but still link dynamically to libc and friends:

    $ go build -compiler gccgo -gccgoflags '-static-libgo' hello.go
    $ readelf -d hello
    Dynamic section at offset 0x128068 contains 28 entries:
      Tag        Type                         Name/Value
     0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
     0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
     0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2] 
    

    Link everything statically:

    $ go build -compiler gccgo -gccgoflags '-static' hello.go
    $ readelf -d hello
    There is no dynamic section in this file.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解