Skip to content
Latchkey

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 status

Common causes

How to fix it

Read the real error above

  1. Scroll up to the ld errors preceding the collect2 line.
  2. 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 missing

How 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.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card