# 在main包中缺少init函数

- **ID:** `go/missing-init-function`
- **领域:** go
- **类别:** compile_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Go要求main包中有main()函数用于可执行程序，但编译器仅在引用时检查init()函数；当包期望一个未定义的init()函数时会出现此错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |

## 解决方案

1. ```
   Ensure the main package has a main() function defined with the correct signature: func main()
   ```
2. ```
   If the package is a library (non-main), change the package declaration to something other than main
   ```

## 无效尝试

- **** — This only works if the package actually requires init() for initialization; often the real issue is a missing main() function or import cycle. (60% 失败率)
- **** — Test files are not compiled in normal builds; this hides the real problem. (95% 失败率)
