go
build_error
ai_generated
true
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%Fix Rate
87%Confidence
0Evidence
2025-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Dynamic library (`.so`) not in standard library paths or `LD_LIBRARY_PATH`.
generic中文
动态库(`.so`)不在标准库路径或`LD_LIBRARY_PATH`中。
Workarounds
-
90% success Set `LD_LIBRARY_PATH` before running
export LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH ./program
-
85% success Use `-rpath` in LDFLAGS with absolute path
// #cgo LDFLAGS: -rpath,/path/to/lib -L/path/to/lib -lfoo
Dead Ends
Common approaches that don't work:
-
Copying .so to current directory
70% fail
Current directory not searched by default.
-
Using `-rpath` without absolute path
50% fail
Relative rpath may break if binary moved.