donglou1866 2016-09-16 14:12
浏览 403
已采纳

如何将-tags netgo设置为go的默认设置?

To compile my golang package so that it produces a statically linked executable, I must say:

go install -tags netgo

Additionally I now realise that on a system without gcc, I must:

go get -tags netgo github.com/mypackage/...
go test -tags netgo ./...

If you're typing this all the time it's no so nice. I have aliases set up so I can type less, but is there a "nicer" or "proper" way to set -tags netgo as some kind of default? Ideally as part of my package itself, so a stranger trying to work with my package doesn't miss the -tags netgo.

Edit: I also want the possibility to say:

go install -tags netgo -ldflags '-linkmode external -extldflags -static -w'

Ie. link to C code that can be statically compiled. So it working on a machine without GCC is less important to me than it producing a statically linked executable. I just wonder if there's a way to do the latter without saying -tags netgo all the time.

  • 写回答

1条回答 默认 最新

  • dsdvr06648 2016-09-16 14:14
    关注

    You can disable cgo altogether by setting CGO_ENABLED=0 which will prevent the net package from linking to the host resolver.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器