doulu1945 2018-08-23 11:37
浏览 38

去构建找不到由Dep确保的供应商软件包

I'm running into an error where vendor packages are not being correctly resolved by go; on macOS High Sierra 10.13.6. I'll use github.com/gorilla/mux as an example package

$ echo $GOPATH
/Users/gregorysims/go

$ go version
go version go1.11 darwin/amd64 

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gregorysims/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gregorysims/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/tb/6c5vksm558q5q4t0fxfscgy80000gp/T/go-build409352678=/tmp/go-build -gno-record-gcc-switches -fno-common"

I'm importing the package with

import (
    ...
    "github.com/gorilla/mux"
    ...
)

When running:

go build -o out main.go

I get the following error for each package in vendor

main.go:6:2: cannot find package "_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux" in any of:
/usr/local/go/src/_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (from $GOPATH)

The folder should be found at

/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux

and is present in the directory.

Why is this being prefixed the following?

/Users/gregorysims/go/src/_

UPDATE

After deleting the local project and recloning from remote, I attempted to build without having any of the dependencies downloaded. This had the expected output:

main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/github.com/gorilla/mux (from $GOPATH)

The above error is produced only after the build command is run after dep ensure is run.

UPDATE 2

Creating an empty vendor directory changes the output to:

main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (vendor tree)
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/github.com/gorilla/mux (from $GOPATH)

Update 3

To simulate dep I called go get github.com/gorilla/mux followed by:

mv $GOPATH/src/github.com/gorilla/mux $GOPATH/src/site/user/project/vendor/github.com/gorilla/mux

After doing so, the problem surfaces again.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程