go mod build subdir

https://stackoverflow.com/questions/63871687/golang-build-cannot-find-module-for-path-mnt-c-xxxxx

 

Golang build cannot find module for path _/mnt/c/XXXXX

Asked 4 months ago
Active 3 months ago
Viewed 243 times
 
0

My system is WSL 2 in Windows 10.

 OS: Debian 10 buster
 Kernel: x86_64 Linux 4.19.104-microsoft-standard
 Shell: zsh 5.7.1
 CPU: AMD Ryzen 9 4900HS with Radeon Graphics @ 16x 2.994GHz

Golang info:

go version go1.15.2 linux/amd64
GOROOT="/usr/local/go"
GOPATH="/mnt/c/workspace/6.824"

And I met a problem when I build a project by plugin model:

$ go build -buildmode=plugin ../mrapps/wc.go
build command-line-arguments: cannot find module for path _/mnt/c/workspace/6.824/src/mr

It is so strange that "_/mnt"

How can I solve it? Why has a "_" before the path?

Help me, please.

2 Answers

1

I would try and use go mod instead of relying on GOPATH

unset GOPATH
cd /mnt/c/workspace/6.824/
go mod init "yourProject"
go build -buildmode=plugin mrapps/wc.go
  •  
    First, thank you for this answer. but I tried follow your command, and it does not work out. I had used docker to solve this problem. But I still want to know the reason for my issue. – Xiangxuan Qu Sep 21 '20 at 9:51 
 
0

You are using go mod. And you can try the following command to fix:

cd 6.824
go mod init "6.824-golabs-2020" 
# change file src/mrapps/wc.go line9 to `import "6.824-golabs-2020/src/mr"`
cd src
go build -buildmode=plugin mrapps/wc.go

More details about mod you can refer to https://golang.org/ref/mod

posted @ 2021-02-08 14:22  zJanly  阅读(216)  评论(0编辑  收藏  举报