我在导入包时遇到问题。我想导入"golang.org/x/tools/cmd/oracle"
和"golang.org/x/tools/oracle"
包。
导入这些包的正确方法是什么?
这是我尝试导入包的方式:
package main
import (
"fmt"
"strings"
"os"
"os/exec"
"golang.org/x/tools/oracle"
"golang.org/x/tools/cmd/oracle"
)
最后两个导入导致以下问题:
==================== Starting Go build ====================
Cleared problem markers for ProjektGO.
************ Building Go project: ProjektGO ************
with GOPATH: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO
>> Running: /usr/lib/go/bin/go install -v -gcflags "-N -l" ./...
file/main.go:13:2: cannot find package "golang.org/x/tools/cmd/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/cmd/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/cmd/oracle (from $GOPATH)
file/main.go:12:2: cannot find package "golang.org/x/tools/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle (from $GOPATH)
^^^ Terminated, exit code: 1 ^^^
************ Build terminated. ************
然后我尝试了这样的事情:
package main
import (
"fmt"
"strings"
"os"
"os/exec"
"../../../../../golang.org/x/tools/cmd/oracle"
"../../../../../golang.org/x/tools/oracle"
)
结果是这样的:
==================== Starting Go build ====================
************ Building Go project: ProjektGO ************
with GOPATH: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO
>> Running: /usr/lib/go/bin/go install -v -gcflags "-N -l" ./...
can't load package: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/file/main.go:11:2: import "../../../../../golang.org/x/tools/cmd/oracle" is a program, not an importable package
../../../../golang.org/x/tools/oracle/describe.go:20:2: cannot find package "golang.org/x/tools/go/ast/astutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ast/astutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ast/astutil (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:26:2: cannot find package "golang.org/x/tools/go/buildutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/buildutil (from $GOPATH)
../../../../golang.org/x/tools/oracle/callers.go:11:2: cannot find package "golang.org/x/tools/go/callgraph" in any of:
/usr/lib/go/src/golang.org/x/tools/go/callgraph (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/callgraph (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:27:2: cannot find package "golang.org/x/tools/go/loader" in any of:
/usr/lib/go/src/golang.org/x/tools/go/loader (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/loader (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:17:2: cannot find package "golang.org/x/tools/go/pointer" in any of:
/usr/lib/go/src/golang.org/x/tools/go/pointer (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/pointer (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:18:2: cannot find package "golang.org/x/tools/go/ssa" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ssa (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ssa (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:19:2: cannot find package "golang.org/x/tools/go/ssa/ssautil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ssa/ssautil (from $GOPATH)
../../../../golang.org/x/tools/oracle/describe.go:22:2: cannot find package "golang.org/x/tools/go/types/typeutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/types/typeutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/types/typeutil (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:28:2: cannot find package "golang.org/x/tools/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:20:2: cannot find package "golang.org/x/tools/oracle/serial" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle/serial (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle/serial (from $GOPATH)
../../../../golang.org/x/tools/oracle/implements.go:21:2: cannot find package "golang.org/x/tools/refactor/importgraph" in any of:
/usr/lib/go/src/golang.org/x/tools/refactor/importgraph (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/refactor/importgraph (from $GOPATH)
^^^ Terminated, exit code: 1 ^^^
************ Build terminated. ************
我的 GOROOT 是/usr/lib/go
,我的 GOPATH 是/home/haapoo/go
. 我知道关于 gopath 和 goroot 的问题经常出现,但也许有人有想法。
PS:我用goclipse
问候哈普