go build_error ai_generated true

错误:未找到 #include <foo.h>

error: #include <foo.h> not found

ID: go/cgo-cflags-missing-include

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-04-20首次发现

版本兼容性

版本状态引入弃用备注
1.19 active
1.20 active

根因分析

CGo预处理器找不到头文件,因为未指定包含路径。

English

CGo preprocessor cannot find the header file because include path not specified.

generic

解决方案

  1. 90% 成功率 Add `// #cgo CFLAGS: -I/path/to/include`
    // #cgo CFLAGS: -I/usr/local/include
    // #include <foo.h>
    import "C"
  2. 85% 成功率 Use `pkg-config` for automatic include paths
    // #cgo pkg-config: foo
    // #include <foo.h>
    import "C"

无效尝试

常见但无效的做法:

  1. Copying header to current directory 30% 失败

    Works but not scalable; may miss other headers.

  2. Using `-I.` without relative path 50% 失败

    Only works if header in current dir.