go build_error ai_generated true

error: #include <foo.h> not found

ID: go/cgo-cflags-missing-include

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-04-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.19 active
1.20 active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. Copying header to current directory 30% fail

    Works but not scalable; may miss other headers.

  2. Using `-I.` without relative path 50% fail

    Only works if header in current dir.