doubaran2438 2018-06-24 09:28
浏览 12

在项目目录中找不到包

I've been trying to solve this problem for the past two hours. I cannot, for the life of me, understand how the folks who developed Go did such a fine job with the language but such a terrible job with package management.

Here is my go env output:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/<me>/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<me>/Documents/Proj/go"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z4/b3lxy_51405_b8pb_680l4xh0000gn/T/go-build063693521=/tmp/go-build -gno-record-gcc-switches -fno-common"

Notice that my GOPATH and GOROOT are set.

Here is the structure of my go workspace (/Users/<me>/Documents/Proj/go):

go/
|-bin/
|-pkg/
|-src/
  |--github.com/
    |--user/
      |--myproject/
        |--client/
          |--client.go
        |--main.go

Here is my client.go file:

// client.go
package client

type MyClient struct {}

this is my main.go file:

// main.go
package main

import "client"

func main() {}

When I run go build in the project root, I get this error:

main.go:4:2: cannot find package "client" in any of:
    /usr/local/opt/go/libexec/src/transport (from $GOROOT)
    /Users/<me>/Documents/Proj/go/src/transport (from $GOPATH)

The first time this happened, I tried to correct the path above:

// main.go
package main

import "github.com/user/myproject/client"

func main() {}

Then I got this error:

main.go:4:2: cannot find package "client" in any of:
    /usr/local/opt/go/libexec/src/transport (from $GOROOT)
    /Users/<me>/Documents/Proj/go/src/github.com/user/myproject/transport (from $GOPATH)

Which is bizarre, since the package exists at that exact path.

What am I doing wrong??

  • 写回答

1条回答 默认 最新

  • dtx63505 2018-06-24 12:04
    关注

    You should not import client but which path is coming from GOPATH/src, in this particular case github.com/user/myproject/client because that is your path.

    I see that the way you describe your problem is not exactly the way it is on your computer. You replaced some things. That is understandable, you do not want to tell the world how your computer looks like. So you replaced your name with "<me>".

    You also replaced the projectname, with MyProject in your question, that is also, just like the user name, a potential spot for an error which we cannot see, because you replaced it. Never use long names in development-paths on Windows, because Windows is doing dirty tricks with them, sometimes.

    I am sure there is something the matter which is a problem. Try using your short-directory name in the go-path. Check this: https://superuser.com/questions/1182040/strange-short-path-name-on-windows

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向