go build_error ai_generated true

# pkg-config: exec: "pkg-config": executable file not found in $PATH

ID: go/missing-cgo-pkg-config

Also available as: JSON · Markdown · 中文
88%Fix Rate
82%Confidence
1Evidence
2024-02-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Go 1.21 active
Go 1.22 active
pkg-config 0.29.2 active

Root Cause

CGo packages requiring pkg-config for dependency resolution cannot find the pkg-config tool in the system PATH.

generic

中文

需要pkg-config进行依赖解析的CGo包在系统PATH中找不到pkg-config工具。

Official Documentation

https://pkg.go.dev/cmd/cgo

Workarounds

  1. 95% success Install pkg-config using the system package manager (e.g., apt-get install pkg-config on Debian/Ubuntu, brew install pkg-config on macOS)
    Install pkg-config using the system package manager (e.g., apt-get install pkg-config on Debian/Ubuntu, brew install pkg-config on macOS)
  2. 85% success Set PKG_CONFIG_PATH environment variable to point to custom pkg-config location if installed in non-standard path
    Set PKG_CONFIG_PATH environment variable to point to custom pkg-config location if installed in non-standard path

中文步骤

  1. Install pkg-config using the system package manager (e.g., apt-get install pkg-config on Debian/Ubuntu, brew install pkg-config on macOS)
  2. Set PKG_CONFIG_PATH environment variable to point to custom pkg-config location if installed in non-standard path

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Many CGo packages are essential for system-level operations; disabling CGo breaks compilation.

  2. 60% fail

    Some packages cannot be compiled without CGo; this only works for pure Go packages.