“软件包XXX不在GOROOT中"在构建Golang项目时 [英] "package XXX is not in GOROOT" when building Golang project

查看:78
本文介绍了“软件包XXX不在GOROOT中"在构建Golang项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我中断这个项目时,出现了一个奇怪的问题.启动Goland后,在尝试运行我的项目时,我到处都是错误.

I have a weird issue that arose when I took a break from this project. Upon starting up Goland, I'm riddled with errors when trying to run my project.

构建我的一个程序包时,特定的错误是: start.go:包项目/游戏不在GOROOT中(C:\ Go \ src \ project \ game)

The specific error, when building one of my packages, is: start.go: package project/game is not in GOROOT (C:\Go\src\project\game)

我在 C:\ Users \ username

go
|-src
   |-project
        |-game
            |-entity
                 |-whatever.go
            |-game_stuff.go
        |-server

我的环境变量就是这样:

and my env vars are as such:

GOROOT=C:\Go 
GOPATH=C:\Users\ketchup\go 

对于每个模块(项目/游戏/实体,项目/游戏,项目/服务器),我都做了 git mod init .

for each of the modules (project/game/entity, project/game, project/server), I did a git mod init.

在构建时,Goland将尝试运行此命令:

When building, Goland will try to run this:

C:\Go\bin\go.exe build -o C:\Users\ketchup\AppData\Local\Temp\___go_build_project_server.exe project/server

并返回错误.

有人可以帮助我解决这个问题吗?自从Goland上次打开它时,它运转良好以来,有点失落.甚至也不知道应该看哪个方向-我对Go还是很陌生,我也不确定要看什么文档:\谢谢大家!

Can anyone help me with this issue? Kind of lost since Goland was working fine the last time I opened it. Also not even sure what direction to look at - I'm pretty new to Go and I'm not really sure what documentation to look at :\ Thank you everyone!

推荐答案

一个很愚蠢的结论(主要是我的意思),但是我的问题来自在每个文件夹中执行 go mod init .从我在其中进行了 go mod init 的每个文件夹中删除 go.mod go.dep 之后,我可以毫无问题地进行构建(通过终端)

A pretty dumb conclusion (mostly on my part) but my issue came from having done go mod init in each of the folders. after removing go.mod and go.dep from each of the folders I did go mod init in, I could build without issue (through terminal)

此外,由于在设置"中启用了转到模块",因此未检测到我在GoLand中的软件包.我禁用了它,GoLand能够索引外部软件包和我自己的软件包.

Also, my packages in GoLand were not being detected because I had Go Modules enabled in the Settings. I disabled it and GoLand was able to index the external packages and my own packages.

这篇关于“软件包XXX不在GOROOT中"在构建Golang项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆