[英]Using 'go build' fetches dependencies even though they are in vendor/
[英]GO Language Dependencies using build
我不认为我是唯一可能对此感到困惑的人。
我有一个非常简单的Go程序,唯一的依赖项是。
import (
"fmt"
"time"
)
我使用了“ go build myprogram.go”,并获得了运行良好的二进制文件(因为我已经安装了GO)
但是,如果其他人没有安装GO,他们似乎会出错。
例如:
open c:\go\lib\time\zoneinfo.zip: The system cannot find the path specified.
panic: time: missing Location in call to Time.In
我需要怎么做才能在构建中包含第三方库?
我想生成一个可以在任何平台上运行的Binary,而不必担心依赖关系
没有完整的代码示例,很难回答特定的问题,但是我要生成独立的二进制文件是:
CGO_ENABLED=0 go build -v -a -ldflags '-s -w' ./...
它将构建至少没有libc依赖项的静态二进制文件……似乎zoneinfo.zip依赖项不会被覆盖。
zoneinfo.zip文件不是Go所独有的。Go希望将其安装在系统上。 以下是扫描系统文件夹中该文件的代码: https : //golang.org/src/time/zoneinfo_unix.go#L31
在撰写本文时:
var zoneDirs = []string{
"/usr/share/zoneinfo/",
"/usr/share/lib/zoneinfo/",
"/usr/lib/locale/TZ/",
runtime.GOROOT() + "/lib/time/zoneinfo.zip",
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.