dongqishun6409 2015-11-02 11:23
浏览 135

如何使用gccgo构建静态程序

I has a prblem when I use gccgo to build static programe version

1> use go build go build -compiler gccgo -gccgoflags '-static -L/lib64' test.go result:

/usr/bin/ld: cannot find -lgo
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc

2>use gccgo build gccgo -o test_gccgo_yes -static -L/lib64 test.go result:

/usr/bin/ld: cannot find -lgo
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc

3> if I don't use static to compile it gccgo -o test_gccgo_yes -g test.go result : ldd test_gccgo_yes show test_gccgo_yes is dynamic file

How I can build static program with gccgo?

  • 写回答

1条回答 默认 最新

  • dongpao2871 2016-06-20 08:58
    关注

    If you're using static then gccgo requires the static versions of each library i.e. libc.a rather than the dynamic libs libc.so.

    Install your distro's static packages. On CentOS 7, they are named glibc-static and libgo-static. Then you should be able to build (you won't need the -L flag either)

    However, you may still get some warnings and possibly errors after that. For example when building one such static application I got these errors:

    /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
    

    So more work may be required to get a working static binary. See https://www.akkadia.org/drepper/no_static_linking.html

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP