我不认为我是唯一可能被这个困惑的人。
我有一个非常简单的Go程序,唯一的依赖是。
import ( "fmt" "time" )我使用“去建立myprogram.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我需要做什么才能在构建中包含第三方库?
我想生成一个二进制文件,可以在任何平台上运行,而不用担心依赖关系
I don't think I'm the only one that might be confused by this.
I have a very simple Go Program, the only dependencies are.
import ( "fmt" "time" )I used "go build myprogram.go" , and get a binary that runs fine (since I have GO installed)
However, if someone else does not have GO installed they seem to get errors.
For Example:
open c:\go\lib\time\zoneinfo.zip: The system cannot find the path specified. panic: time: missing Location in call to Time.InWhat do I need to do to include third party libraries in the build ?
I'd like to generate a Binary that will run on any Platform without worrying about dependencies
最满意答案
如果没有你的代码的更完整的例子,很难回答具体问题,但我做什么来生成独立的二进制文件是:
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", }Without a fuller example of your code, it's hard to answer the specific issue, but what I do to generate standalone binaries is:
CGO_ENABLED=0 go build -v -a -ldflags '-s -w' ./...Which builds a static binary without libc dependencies at least... It seems the zoneinfo.zip dependency wouldn't be covered by that.
The zoneinfo.zip file is not unique to Go... Go expects it to be installed on the system. Here is the code that scans system folders for that file: https://golang.org/src/time/zoneinfo_unix.go#L31
At time of writing:
var zoneDirs = []string{ "/usr/share/zoneinfo/", "/usr/share/lib/zoneinfo/", "/usr/lib/locale/TZ/", runtime.GOROOT() + "/lib/time/zoneinfo.zip", }更多推荐
发布评论