运行 go mod tidy 后出现警告 could not import C,且无法编译。

1. 运行环境#

系统环境:Windows10
Go 版本: go1.18.3 windows/amd64
系统构建:Gin
数据模型:GORM

2. 问题描述?#

使用 go get gorm.io/gorm 引入包,按照教程将 config/database.go 文件,.env 文件,pkg/database/database.go 文件,bootstrap/database.go 文件建好后,修改 main.go 文件,再运行 go mod tidy 后,出现警告 could not import C (cgo preprocessing failed) (compile)。

错误提示:

[{
    "resource": "/c:/Program Files/Go/src/runtime/cgo/cgo.go",
    "owner": "go-staticcheck",
    "severity": 4,
    "message": "could not import C (cgo preprocessing failed) (compile)",
    "source": "go-staticcheck",
    "startLineNumber": 34,
    "startColumn": 8,
    "endLineNumber": 34,
    "endColumn": 9
}]

错误文件:C:\Program Files\Go\src\runtime\cgo\cogo.go

sreio
最佳答案

cgo 没有开启吧

2年前 评论