I'm trying to compile a basic C++ program for school and when I try running it from the Mac Terminal (10.7.6), I get this message:
ld: library not found for -lgcc_ext.10.5
collect2: error: ld returned 1 exit status
I'm definitely in the correct directory and installed XCode Command Line tools. Here is my command prompt:
g++ -o chapter_2 hello_world.cpp
Here is my basic c++ program.
#include <iostream>
using namespace std;
int main(){
cout << "Hello world" << endl;
}
As Judd pointed out, the issue is that the linker can't find libgcc_ext.10.5. While I don't have an ideal solution for this, what worked for me was installing gcc-4.8 using homebrew, and using a newer gcc.
brew install gcc48
I believe there is even gcc49 now. Using this I was able to compile without problems (though note that I had to use $ gcc-4.8 ...
in the console, as $ gcc ...
still points to the older gcc version (unless you explicitly change that).
I had the same problem, on OS X 10.8, with both current XCode and gcc installed by Homebrew.
When I checked $ which g++
it gave /usr/local/bin/g++
.
So I commented this path in .bash_profile
:
#PATH="/usr/local/bin:${PATH}"
Now $ which g++
gives /usr/bin/g++
and its version indicates that it is from XCode and there is no ld: library not found for -lgcc_ext.10.5
error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With