码迷,mamicode.com
首页 > 其他好文 > 详细

golang 条件编译

时间:2020-02-02 14:16:25      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:编写   Plan   property   cgo   span   需要   comment   rap   net   

很多时候对于不同的平台需要编写不同的代码,可选的方式

build tag

  • 参考格式
// +build
  • 对于平台处理的例子
// +build linux,386 darwin,!cgo

文件后缀

  • 参考格式
_$GOOS.go
_$GOOS_$GOARCH.go
  • 参考例子
mypkg_freebsd_arm.go  
mypkg_plan9.go  

如何选择

对于对于构建需要特定平台关联(排他性),可以使用build tag,或者需要平台hotfix (都支持),可以使用文件后缀,下边的链接有说明

参考资料

https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool
https://github.com/rongfengliang/go-build-tag-file-suffix

golang 条件编译

标签:编写   Plan   property   cgo   span   需要   comment   rap   net   

原文地址:https://www.cnblogs.com/rongfengliang/p/12251836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!