问题:需要用vscode打开 没有用 go.mod
管理的项目 打包项目为linux执行的二进制文件
vscode 全局 settings.json
配置
{
"go.formatTool": "gofmt",
"go.gopath": "D:\\GoPath;",
"go.goroot": "D:\\GO",
"go.lintTool": "golint",
"debug.console.fontSize": 16,
"debug.console.lineHeight": 30,
"gopls": {
"ui.semanticTokens": true
},
"go.toolsEnvVars": {
"GO111MODULE": "auto",
},
}
打包命令:
set CGO_ENABLED=0
set GOARCH=amd64
set GOOS=linux
#如果set命令报错把上述set 换成 go env -w
go build -o name
运行结果:
go build -o name
main.go:4:2: cannot find package "HeroOkWebGo/src/RpcServer" in any of:
D:\GO\src\HeroOkWebGo\src\RpcServer (from $GOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer (from $GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer(fromGOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\RpcServer(fromGOPATH)
main.go:5:2: cannot find package "HeroOkWebGo/src/action" in any of:
D:\GO\src\HeroOkWebGo\src\action (from $GOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\action (from $GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\action(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\action (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\action(fromGOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\action(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\action (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\action(fromGOPATH)
main.go:6:2: cannot find package "HeroOkWebGo/src/actionweb" in any of:
D:\GO\src\HeroOkWebGo\src\actionweb (from $GOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\actionweb (from $GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\actionweb(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\actionweb (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\actionweb(fromGOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\actionweb(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\actionweb (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\actionweb(fromGOPATH)
main.go:7:2: cannot find package "HeroOkWebGo/src/service" in any of:
D:\GO\src\HeroOkWebGo\src\service (from $GOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\service (from $GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\service(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\service (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\service(fromGOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\service(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\service (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\service(fromGOPATH)
main.go:8:2: cannot find package "HeroOkWebGo/src/util" in any of:
D:\GO\src\HeroOkWebGo\src\util (from $GOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\util (from $GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\util(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\util (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\util(fromGOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\util(fromGOROOT)
C:\Users\20705\go\src\HeroOkWebGo\src\util (from
GOROOT)C:\Users\20705\go\src\HeroOkWebGo\src\util(fromGOPATH)
main.go:17:2: cannot find package "github.com/gorilla/context" in any of:
D:\GO\src\github.com\gorilla\context (from $GOROOT)
C:\Users\20705\go\src\github.com\gorilla\context (from $GOROOT)C:\Users\20705\go\src\github.com\gorilla\context(fromGOROOT)
C:\Users\20705\go\src\github.com\gorilla\context (from
GOROOT)C:\Users\20705\go\src\github.com\gorilla\context(fromGOROOT)C:\Users\20705\go\src\github.com\gorilla\context(fromGOROOT)
C:\Users\20705\go\src\github.com\gorilla\context (from
GOROOT)C:\Users\20705\go\src\github.com\gorilla\context(fromGOPATH)
main.go:18:2: cannot find package "github.com/keep94/weblogs" in any of:
D:\GO\src\github.com\keep94\weblogs (from $GOROOT)
C:\Users\20705\go\src\github.com\keep94\weblogs (from $GOROOT)C:\Users\20705\go\src\github.com\keep94\weblogs(fromGOROOT)
C:\Users\20705\go\src\github.com\keep94\weblogs (from
GOROOT)C:\Users\20705\go\src\github.com\keep94\weblogs(fromGOROOT)C:\Users\20705\go\src\github.com\keep94\weblogs(fromGOROOT)
C:\Users\20705\go\src\github.com\keep94\weblogs (from
GOROOT)C:\Users\20705\go\src\github.com\keep94\weblogs(fromGOPATH)
处理方式
$env:GOPATH="D:\GoPath;C:\Users\XXXX\go"
# C:\Users\XXXX\go 为默认gopath
#上述方法只适用于 当前命令行,每次打开项目都需运行
最优解:
在项目目录下的 .vscode
目录下的 settings.json
文件中添加一下内容,重新打开项目即可
{
"terminal.integrated.env.windows": {
//旧model项目默认设置
"GOPATH": "D:\GoPath;C:\Users\XXXX\go"
}
}
标签:src,Users,vscode,20705,GOROOT,go,打开,HeroOkWebGo
From: https://www.cnblogs.com/newcxp/p/17870692.html