当我使用gccgo构建静态程序版本时,我遇到了一个问题
使用go build go build -compiler gccgo -gccgoflags‘- 1> -L/lib64’test.go结果:
/usr/bin/ld: cannot find -lgo
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc2>use gccgo构建gccgo -o test_gccgo_yes -static -L/lib64 test.go结果:
/usr/bin/ld: cannot find -lgo
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc如果我不使用静态编译,gccgo -o test_gccgo_yes -g test.go结果: ldd test_gccgo_yes 3> test_gccgo_yes is dynamic file
如何使用gccgo构建静态程序?
发布于 2016-06-20 16:58:21
如果您使用的是static,那么gccgo需要每个库的静态版本,即libc.a,而不是动态库libc.so。
安装发行版的静态包。在CentOS 7上,它们被命名为glibc-static和libgo-static。然后您应该能够构建(您也不需要-L标志)
但是,在此之后,您可能仍会收到一些警告和可能的错误。例如,当构建一个这样的静态应用程序时,我得到了以下错误:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgo.a(net.o): In function `net.lookupPort':
(.text+0x48e2): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie因此,可能需要做更多的工作才能获得有效的静态二进制文件。请参阅https://www.akkadia.org/drepper/no_static_linking.html
https://stackoverflow.com/questions/33476470
复制相似问题