After a brew upgrade every time I try to compile a .c file I get the following error:

ld: library not found for -lgcc
collect2: error: ld returned 1 exit status

Wrappers like mpicc still work though. I tried relinking with brew link --overwrite gcc, but got no working results, as it is already linked. brew doctor doesn't give me a hint.

  • What is library gcc? What is the full line you are using to compile? .c files are compiled to .o and are not linked. Why use brew's gcc rather than Apple's clang? – user151019 Jun 21 '16 at 11:10
  • @Mark, just compiling a simple Hello World program with gcc -o helloworld helloworld.c fails and shows that error. – tulians Jun 21 '16 at 11:12
  • Where is gcc i.e. what does type -p gcc show – user151019 Jun 21 '16 at 11:13
  • It's in /usr/local/bin/gcc – tulians Jun 21 '16 at 11:14
  • See github.com/Homebrew/legacy-homebrew/issues/40653 what version of Xcode do you have – user151019 Jun 21 '16 at 11:34

I'm not sure with it's like this, but if I compile with gcc-4.9 (as the gcc version I have instaled is version 4.9.2) instead of gcc it works as it should. So the compilation sentence that seems to work is gcc-4.9 -o exec_name program.c. If someone knows why it is like this I would be interested to know.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .