# 错误：对`some_function'的未定义引用

- **ID:** `go/cgo-ldflags-ordering`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

`LDFLAGS`中的库顺序很重要；如果一个库依赖于另一个库，它必须放在后面。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |

## 解决方案

1. **Order libraries so that dependencies come after dependents** (90% 成功率)
   ```
   // #cgo LDFLAGS: -lbar -lfoo  // if foo depends on bar
   ```
2. **Use `-Wl,--as-needed` to allow reordering** (80% 成功率)
   ```
   // #cgo LDFLAGS: -Wl,--as-needed -lfoo -lbar
   ```

## 无效尝试

- **Adding `-lfoo` multiple times** — Does not fix dependency order. (60% 失败率)
- **Using `-Wl,--start-group ... --end-group` incorrectly** — May cause circular dependency issues. (40% 失败率)
