go build_error ai_generated true

# pkg-config: exec: "pkg-config": 在$PATH中找不到可执行文件

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

ID: go/missing-cgo-pkg-config

其他格式: JSON · Markdown 中文 · English
88%修复率
82%置信度
1证据数
2024-02-20首次发现

版本兼容性

版本状态引入弃用备注
Go 1.21 active
Go 1.22 active
pkg-config 0.29.2 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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

无效尝试

常见但无效的做法:

  1. 95% 失败

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

  2. 60% 失败

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