-static和-static-libgo对于gccgo有什么区别?这些文档似乎并没有真正揭示正在发生的事情:
-static-libgo选项静态地链接编译后的包。-static选项可以执行完全静态链接( gc编译器的默认设置)。-static-libgo仅仅是静态链接libgo.a吗?而-static是完整的glibc库吗?
发布于 2014-02-25 10:40:06
检查生成的ELF中的动态链接:
gc静态构建:
$ go build hello.go
$ readelf -d hello
There is no dynamic section in this file.默认情况下,gccgo针对libgo、libc等进行动态链接:
$ 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]将libgo放入可执行文件中,但仍然动态地链接到libc和朋友:
$ 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] 静态地将所有事物联系起来:
$ go build -compiler gccgo -gccgoflags '-static' hello.go
$ readelf -d hello
There is no dynamic section in this file.https://stackoverflow.com/questions/20369106
复制相似问题