douweng5420 2017-09-15 19:18
浏览 296

在VS Code中调试项目时出错的gopath

From one day to the next I can't manage to debug a project where everything worked perfectly before. I'm sure I haven't changed anything about the project or its settings during this time. All I did was work on another project in the same IDE (VS Code).

The actual error in VS Code:

dbInteraction.go:8:2: cannot find package "github.com/go-sql-driver/mysql" in any of:
C:\Go\src\github.com\go-sql-driver\mysql (from $GOROOT)
c:\Users\Mani\Documents\Programmier Projekte\PRJCTNAME\src\github.com\go-sql-driver\mysql (from $GOPATH)
main.go:8:2: cannot find package "github.com/gorilla/mux" in any of:
C:\Go\src\github.com\gorilla\mux (from $GOROOT)
c:\Users\Mani\Documents\Programmier Projekte\PRJCTNAME\src\github.com\gorilla\mux (from $GOPATH)
exit status 1
Process exiting with code: 1

Checking the environment variables:

C:\Users\Mani>echo %GOPATH%
C:\Users\Mani\go

C:\Users\Mani>echo %GOROOT%
C:\Go\

As you can see, my environment variables are set as desired and the $GOPATH in the debug output does not match this path; in contract it is the actual path of my go sources for this project.

When i build the project over the command line with go build (in the project directory) it works perfectly. That gives me the suspicion that VS Code is responsible for the problem.

The user settings and workspace settings in VS Code are both empty. Also empty is the project specific VS-Code settings.go and the launch.go has not changed from the default.

EDIT 1: If i remember correctly, i think I switched from VS Code 32bit to VS Code 64bit in between.

EDIT 2: After setting the env parameter in the launch.json I am able to debug the program again but now i do not get any output in the debug console.

  • 写回答

1条回答 默认 最新

  • duan1979768678 2017-09-15 20:00
    关注

    If you're using the vscode-go extension, try changing the go.gopath setting as described on the Microsoft vscode-go wiki:

    Setting go.gopath in User settings overrides the GOPATH that was derived from the above logic. Setting go.gopath in Workspace settings overrides the one from User settings. You can set multiple folders as GOPATH in this setting. Note that they should be ; separated in Windows and : separated otherwise.

    I initially had problems with Visual Studio Code recognising my gopath, and this fixed it.

    评论

报告相同问题?

悬赏问题

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