# ld: symbol 'foo' has multiple definitions (from object files a.o and b.o)

- **ID:** `go/cgo-multiple-definition-symbol`
- **Domain:** go
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

Duplicate symbol definitions across C object files linked via cgo, often due to including the same .c file in multiple packages or using static libraries with conflicting symbols.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Go 1.15 | active | — | — |
| Go 1.16 | active | — | — |
| Go 1.17 | active | — | — |
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |
| Go 1.23 | active | — | — |

## Workarounds

1. **Ensure each .c file is compiled only once by consolidating cgo directives into a single package or using a single .go file with all C code** (85% success)
   ```
   Ensure each .c file is compiled only once by consolidating cgo directives into a single package or using a single .go file with all C code
   ```
2. **Use linker flag -Wl,--allow-multiple-definition to force link but verify behavior** (70% success)
   ```
   Use linker flag -Wl,--allow-multiple-definition to force link but verify behavior
   ```
3. **Refactor to avoid static libraries with overlapping symbols; use dynamic linking or rename symbols via objcopy** (80% success)
   ```
   Refactor to avoid static libraries with overlapping symbols; use dynamic linking or rename symbols via objcopy
   ```

## Dead Ends

- **** — This flag suppresses the error but can cause undefined behavior or crashes due to symbol aliasing. (60% fail)
- **** — If the duplicate comes from a static library you don't control, renaming isn't possible. (50% fail)
- **** — Multiple definitions occur at link time from different .o files, not from header inclusion; pragma doesn't help. (90% fail)
