quorum87
quorum87

Reputation: 91

ld: library not found for -lgcc_ext.10.5

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;

}

Upvotes: 9

Views: 3143

Answers (3)

Piotr Migdal
Piotr Migdal

Reputation: 12872

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.

Upvotes: 1

Nate
Nate

Reputation: 1273

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

Upvotes: 2

Judd Gilbert
Judd Gilbert

Reputation: 3

I'm not a mac guy, but I recognize the issue is that the linker can't find the library, (libgcc_ext.10.5) because your development environment is incorrectly set up. I would expect it to be in /usr/lib or /usr/local/lib or something to that effect. You might try doing a ld --help and see if you can find out how the linker search path is specified. (ld is the program that does the linking, g++ calls it when it is done compiling.) Then find the library on your machine and add that path to the ld search path.

Upvotes: 0

Related Questions