gcc "collect2: error: ld returned 1 exit status" in CI
collect2 is the GCC wrapper that drives the linker. "ld returned 1" only reports that linking failed - the actionable diagnostic is the undefined reference or missing library printed just above.
What this error means
The build ends with collect2 reporting ld returned a non-zero status, preceded by one or more specific linker errors.
ld
/usr/bin/ld: main.o: undefined reference to 'helper'
collect2: error: ld returned 1 exit statusCommon causes
How to fix it
Read the real error above
- Scroll up to the ld errors preceding the collect2 line.
- Fix that specific cause (add the library, the object, or correct link order).
ld
gcc main.o helper.o -o app # add the object that was missingHow to prevent it
- Treat collect2 as a summary line and always act on the specific linker errors that precede it.
Frequently asked questions
How do I fix gcc "collect2: error: ld returned 1 exit status" in CI?
Read the real error above. Scroll up to the ld errors preceding the collect2 line.
What does gcc "collect2: error: ld returned 1 exit status" in CI actually mean?
The build ends with collect2 reporting ld returned a non-zero status, preceded by one or more specific linker errors.
How do I stop gcc "collect2: error: ld returned 1 exit status" in CI happening again?
Treat collect2 as a summary line and always act on the specific linker errors that precede it.