Switching from gb to plain go - how?


(Mouse) #1

I have a project (not mine!) written in Go, which uses gb to build it. It uses a fair amount of dependencies (“vendor” stuff).

Once go moved from 1.11 to 1.12, gb stopped working - it fails to link with the following errors:

golang.org/x/sys/unix.libc_close_trampoline·f: relocation target golang.org/x/sys/unix.libc_close_trampoline not defined for ABIInternal (but is defined for ABI0)
. . . . .
# yubihsm-connector
 yubihsm-connector
    
FATAL: command "build" failed: exit status 2

I would like to build this project manually, replicating what gb build would have done if it worked correctly. Unfortunately, as a complete beginner, I have no clue how Go build system works. Could you advise me on how to build this project manually? Just running go build caused some errors:

    $ go build
    main.go:30:2: cannot find package "github.com/kardianos/service" in any of:
        /usr/local/go/src/github.com/kardianos/service (from $GOROOT)
        . . . . . (from $GOPATH)
    . . . . .

so something must be missing - could you point me at what it is, and how to recreate it?

Thanks!


(Ivan Matmati) #2

Have you checked where the package is actually located ? Did you get it before building ?
What are the values of your GOPATH and GOROOT environment variables ? Did you check if the package is lying there ?


(Mouse) #3

Yes, all the packages seem to be downloaded and located in vendor/src subdirectory of the project, which is $HOME/src/yubihsm-connector.

$ env | grep GO
CGO_LDFLAGS=-L/opt/local/lib
CGO_CFLAGS=-I/opt/local/include
GOARCH=amd64
GOROOT=/opt/local/lib/go
GOOS=darwin
GOPATH=/Users/ur20980/go
$ 

It’s a gb project, so the directory structure is:

--$HOME/src/
                 |
yubihsm-connector/
       |
       |
       --src/yubihsm-connector  (*.go files for the project itself)
       |
       |
       --vendor/
                 |
                 |
                 --src   (all the dependencies/packages)

(Ivan Matmati) #4

You should have your project src directory under your GOPATH directory.


(Mouse) #5

Is there any way around that? Maybe adding to GOPATH some path for the duration of go build?


(Mouse) #6

Based on the above guidance, answering my own question: the following build command worked:

$ cd src/yubihsm-connector && GOPATH="${GOPATH}:${PWD}/vendor" go build

I haven’t experimented with

$ GOPATH="${GOPATH}:${PWD}/src:${PWD}/vendor" go build