淘宝是什么语言做的网站,三合一网站建设口碑好,网站建设需要摊销多久,上海网站建设怎么赚钱Go语言使用时常常会遇到的一些错误及解决方法#xff0c;文中的示例代码讲解详细#xff0c;感兴趣的小伙伴可以了解一下 1、go: go.mod file not found in current directory or any parent directory
go mod init name
2、Failed to build the application: main.go:4:2:… Go语言使用时常常会遇到的一些错误及解决方法文中的示例代码讲解详细感兴趣的小伙伴可以了解一下 1、go: go.mod file not found in current directory or any parent directory
go mod init name
2、Failed to build the application: main.go:4:2: package generateproject/routers is not in GOROOT
go env -w GO111MODULEon
go mod init name
3、 Cannot generate application code outside of application path
切换到对应项目目录中
4、Failed to build the application: # github.com/mattn/go-sqlite3 cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%
安装MinGWDownload mingw-w64-install.exe (MinGW-w64 - for 32 and 64 bit Windows) 5、golang软件代码报红 GOPROXYhttps://goproxy.cn,direct
6、配置IEDE配置GOROOT找不到本地SDK
打开GO的安装目录下的D:\Program Files\Go\src\runtime\internal\sys\zversion.go文件添加一行其中1.22.4为你下载的GO版本号
const TheVersion go1.22.4
7、command-line-arguments main 包中的不同的文件的代码不能相互调用解决
# 方法一
go run main.go a.go# 方法二
# go run ./ 等同于 go run *.go
go run *.go# 方法三
go build
8、go 报错undefined: syscall.SIGUSR1处理 在 go 的安装目录修改Go\src\syscall\types_windows.go增加如下代码
var signals [...]string{
// 这里省略N行
/** 找到此位置添加如下 */
16: SIGUSR1,
17: SIGUSR2,
18: SIGTSTP,}/** 兼容windows start */func Kill(...interface{}) { return;
}const ( SIGUSR1 Signal(0x10) SIGUSR2 Signal(0x11) SIGTSTP Signal(0x12)
)
9、包路径中含有大写字母时导致go mod tidygo mod download等命令无法使用
解决方法go.mod 中添加 replace以github.com/Unknwon/com包为例
replace github.com/Unknwon/com github.com/unknwon/com v0.0.0-20240611-757fff95f3e
10、package xxx is not in std 这个报错的原因是Go程序在编译时找不到依赖的包找了半天这个错误是JDK不完整因为解压的时候数据丢失解决方法我们在将JDK解压至指定目录覆盖即可