0

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.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

user3888307
  • 2,825
  • 5
  • 22
  • 32
  • Possible duplicate of [Is it possible to use the Go compiler to distribute a executable file for other os?](http://stackoverflow.com/questions/13967470/is-it-possible-to-use-the-go-compiler-to-distribute-a-executable-file-for-other) – hlscalon Dec 06 '16 at 18:14
  • 1
    You don't need Go installed to run a Go binary. See the [time.LoadLocation](https://golang.org/pkg/time/#LoadLocation) docs about the zoneinfo.zip file. – JimB Dec 06 '16 at 18:19

1 Answers1

0

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",
}
John Weldon
  • 39,849
  • 11
  • 94
  • 127