go
build_error
ai_generated
true
错误:cgo:未找到动态库:libfoo.so:无法打开共享对象文件:没有那个文件或目录
error: cgo: dynamic library not found: libfoo.so: cannot open shared object file: No such file or directory
ID: go/cgo-dynamic-library-not-found
80%修复率
87%置信度
0证据数
2025-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
动态库(`.so`)不在标准库路径或`LD_LIBRARY_PATH`中。
English
Dynamic library (`.so`) not in standard library paths or `LD_LIBRARY_PATH`.
解决方案
-
90% 成功率 Set `LD_LIBRARY_PATH` before running
export LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH ./program
-
85% 成功率 Use `-rpath` in LDFLAGS with absolute path
// #cgo LDFLAGS: -rpath,/path/to/lib -L/path/to/lib -lfoo
无效尝试
常见但无效的做法:
-
Copying .so to current directory
70% 失败
Current directory not searched by default.
-
Using `-rpath` without absolute path
50% 失败
Relative rpath may break if binary moved.