简体   繁体   English

使用构建GO语言依赖

[英]GO Language Dependencies using build

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. 我有一个非常简单的Go程序,唯一的依赖项是。

import (
    "fmt"
    "time"
   )

I used "go build myprogram.go" , and get a binary that runs fine (since I have GO installed) 我使用了“ go build myprogram.go”,并获得了运行良好的二进制文件(因为我已经安装了GO)

However, if someone else does not have GO installed they seem to get errors. 但是,如果其他人没有安装GO,他们似乎会出错。

For Example: 例如:

open c:\go\lib\time\zoneinfo.zip: The system cannot find the path specified.
panic: time: missing Location in call to Time.In

What 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 我想生成一个可以在任何平台上运行的Binary,而不必担心依赖关系

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. 它将构建至少没有libc依赖项的静态二进制文件……似乎zoneinfo.zip依赖项不会被覆盖。

The zoneinfo.zip file is not unique to Go... Go expects it to be installed on the system. zoneinfo.zip文件不是Go所独有的。Go希望将其安装在系统上。 Here is the code that scans system folders for that file: https://golang.org/src/time/zoneinfo_unix.go#L31 以下是扫描系统文件夹中该文件的代码: 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",
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM