I'm having a problem related with go binary-only package. So I created a very simple go application. Here is the structure:
$ tree -L 2 $GOPATH/src/
/Users/megadestina/Documents/gopath/src/
├── lib
│ └── lib.go
└── ukulele
└── main.go
The lib
folder is library I wanted to distribute as binary only. Where the ukulele
is the main package.
Below is the content of lib/lib.go
:
package lib
import "fmt"
func SayHello() {
fmt.Println("hello there")
}
I performed go install
command on the lib
package, and it's success.
$ go install -a
$ ls $GOPATH/pkg/darwin_amd64 | grep lib.a
lib.a
Then I edited the lib/lib.go
into below:
//go:binary-only-package
package lib
On the main package file ukulele/main.go
, the lib
package is being consumed. Here is the code:
package main
import "lib"
func main() {
lib.SayHello()
}
I run the application and got following error.
$ go run main.go
# command-line-arguments
cannot find package fmt (using -importcfg)
/usr/local/go/pkg/tool/darwin_amd64/link: cannot open file : open : no such file or directory
What should I do to make it work, to make the lib
package distributed as binary-only package?
Fyi, I use go1.11.4
.
$ go version
go version go1.11.4 darwin/amd64
Here is the output of go env
:
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/megadestina/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/megadestina/Documents/gopath"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3h/5t8llxf147j06h5jcmy0474r0000gp/T/go-build021065592=/tmp/go-build -gno-record-gcc-switches -fno-common"