New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: dots in import statement causes error in finding packages under $GOPATH #20391
Comments
We need more details. Please show us the exact file layout of your GOPATH directory for the case that fails. Thanks. |
~/development/go > tree -L 2
9 directories, 1 file |
Thanks, but we really need to see all the files under |
I wouldn't bother to answer at all if I were you. What you ask is ridicolous. You should have warned me before I spent time reporting a problem. |
Do you want us to close this bug, then? |
@bertverhees Why is it ridiculous? Thanks for reporting the problem, but right now we simply don't have enough information to identify and solve it. The error you are reporting is an inability to open |
You asked to see ALL files under src, which is my complete work I wrote in Go. Which I find ridiculous to ask. Now you ask for one file to recreate the problem. That is reasonable. I will do this today. |
#Downloading and installing the antlr package verhees 08:44:27 ~/go > go get github.com/antlr/antlr4/runtime/Go/antlr verhees 08:46:37 ~/go > tree -L 4
9 directories, 0 files verhees 08:55:51 ~/go/src > tree -L 4
#creating the antlr Hello world project, as you can see, I have the generated files all in the directory parser. And I myself have written one file in package main, in the root directory of this project. verhees 08:57:50 ~/go/src/antlr_experiments > tree
3 directories, 8 files When I have the import-statement in the Test.go like this
verhees 09:01:30 ~/go/src/antlr_experiments/code/hello > go run Test.go (this is what the program should do) Now I change it to this
This happens: I have uploaded all files of this project (again, to check my configuration) verhees 09:10:23 ~/go/src/antlr_experiments/code/hello > go env |
I come to this question because of this: It has following text: I think this is an error, to check that I made up this call. |
Thanks for the test case. I can recreate the problem now. This is a complicated scenario. The text you quote explains that relative imports are supported when you aren't in a workspace--that is, when you aren't working under So you are clearly doing something that the go tool isn't designed for. Either work in But that said, what you are trying to do should either work or should give a sensible error message, and right now it does neither. So there is a bug here, although at the moment I'm not sure what the right fix is. |
Thanks, that explains. Hint for the errormessage: It should explain where it searches for the github path, also indicate that I tried to solve it in the relative path. It costed me nearly a day to find out, but worse, the frustration and uncertainty. Specially because I am combining Go with Antlr which is quite new, and everything can go wrong. Thanks for your explanation |
The cited section does make it clear, see the last line. |
thanks for the answer, the difference between |
I will try to clean the error up during some work on cmd/go next cycle. |
I can't reproduce this today, and I think the module loader already has a better error. Closing. Feel free to submit a new bug with a simpler repro case if you are still seeing the confusing error. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8.1 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/verhees/development/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build251409227=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
I did: go get github.com/antlr/antlr4/runtime/Go/antlr
I run the antlr grammar and had the result go-files in the directory parser which is a subdirectory from the project directory (which is again a subdirectory of the $GOPATH/src
I used the library in import like this:
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"./parser"
"os"
"fmt"
)
What did you expect to see?
I expected to see the program (very small program ) run
What did you see instead?
I got an error:
/usr/local/go/pkg/tool/linux_amd64/link: cannot open file /usr/local/go/pkg/linux_amd64/github.com/antlr/antlr4/runtime/Go/antlr.a: open /usr/local/go/pkg/linux_amd64/github.com/antlr/antlr4/runtime/Go/antlr.a: no such file or directory
It was clear that it did not look in the $GOPATH/src diectory for the module.
I found somewhere on the internet something about dots in an import statement, and I changed my import like this:
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"antlr_experiments/JSON_experiment/parser"
"os"
"fmt"
)
And now everything runs fine.
Thanks for reading, I hope this is useful for you.
The text was updated successfully, but these errors were encountered: