1

I have following golang project structure:

- go-projects
  - src
    - github.com
      - user
        - my-project
          - pack
            - pack.go
          - main.go

my GOPATH is:

export GOPATH=/home/user/go-projects

I'm trying to call functions from pack package in main.go file and trying to build this project with:

cd my-project go build && go-install

There is no any output, and also there is no bin directory anywhere. What i did wrong?

UPD This problem was solved. accidently missunderstood file content of main.go and pack.go. But now there is another problem.

How to build correctly this program. When i'm trying to execute go build in /home/user/go-projects/src/github.com/user/my-project i'm getting following erros:

main.go:4:8: cannot find package "github.com/user/pack" in any of:
    /home/user/Downloads/go/src/pkg/github.com/user/pack (from $GOROOT)
    /home/user/go-projects/src/github.com/user/pack (from $GOPATH)

Thank you

1
  • you don't need go build, go install runs that as a preliminary step, but it will create a binary if you're in a main package, which could be confusing. Commented Jun 20, 2014 at 14:51

2 Answers 2

3

While it may be convenient to let the tools infer the package from the current working directory, it doesn't work for much more than a simple main package. Get used to referencing packages by their full import path, and you'll save yourself other problems down the line.

go install github.com/user/pack
Sign up to request clarification or add additional context in comments.

Comments

1

It goes into $GOPATH/bin/my-project, if you wanna test it right away just use go run main.go

1 Comment

thank for the answer, but: 1. i have $GOPATH/bin/ directory but it's empty 2. tried go run main.go i'm getting cannot run non main file, but there is simple hello world - gist.github.com/0xAX/7e077f35defc3631356a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.