dpub33855 2016-05-19 03:58
浏览 153

如何导入golang自己的软件包?

I have problems with importing a package. I want to import the "golang.org/x/tools/cmd/oracle" and the "golang.org/x/tools/oracle" package.

Which is the correct way to import these packages?


This the way I try to import the packages:

package main

import (
    "fmt"
    "strings"
    "os"
    "os/exec"
    "golang.org/x/tools/oracle"
    "golang.org/x/tools/cmd/oracle"
)

The both last imports leads to the following problem:

====================  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.  ************

Then I tried things like that:

package main

import (
    "fmt"
    "strings"
    "os"
    "os/exec"
    "../../../../../golang.org/x/tools/cmd/oracle"
    "../../../../../golang.org/x/tools/oracle"
)

And the result was this:

====================  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.  ************

My GOROOT is /usr/lib/go and my GOPATH is /home/haapoo/go . I know the question about gopath and goroot comes often but maybe anyone has an idea.

PS: I use goclipse

Greetings haapoo

  • 写回答

4条回答 默认 最新

  • doudeng5218 2016-05-19 04:15
    关注

    If you need to import different packages of the same name in Golang, this is the way(just name it):

    import (
        "text/template"
        ht "html/template"
    )
    

    but in case of "golang.org/x/tools/cmd/oracle"
    it is not a package , it has just main.go and you need to build/install it. it is a command line tool:

    Run 'oracle -help' for more information.
    Go source code oracle.
    Usage: oracle [<flag> ...] <mode> <args> ...
    
    The -format flag controls the output format:
            plain   an editor-friendly format in which every line of output
                    is of the form "pos: text", where pos is "-" if unknown.
            json    structured data in JSON syntax.
            xml     structured data in XML syntax.
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器