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 @   zJanly  阅读(218)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示