# 错误：cgo：未找到动态库：libfoo.so：无法打开共享对象文件：没有那个文件或目录

- **ID:** `go/cgo-dynamic-library-not-found`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

动态库（`.so`）不在标准库路径或`LD_LIBRARY_PATH`中。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **Set `LD_LIBRARY_PATH` before running** (90% 成功率)
   ```
   export LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH
./program
   ```
2. **Use `-rpath` in LDFLAGS with absolute path** (85% 成功率)
   ```
   // #cgo LDFLAGS: -rpath,/path/to/lib -L/path/to/lib -lfoo
   ```

## 无效尝试

- **Copying .so to current directory** — Current directory not searched by default. (70% 失败率)
- **Using `-rpath` without absolute path** — Relative rpath may break if binary moved. (50% 失败率)
