I am using Mac OSX 10.11 El Capitan
.
Previously I was using OSX 10.10
. I my older version of OSX I was running gcc 4.9
and g++ 4.9
. But after upgrading to OSX 10.11
all C++ programs starts failing to compile.
Then I switched back to gcc 4.2
in OSX 10.11
and I am getting following error:
Undefined symbols for architecture x86_64:
"Graph::BFS(int)", referenced from:
_main in BFS-e06012.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried all the answers available. I tried these commands to run:
$ g++ -stdlib=libstdc++ BFS.cc -o BFS
$ g++ -lstdc++ BFS.cc -o BFS
$ gcc -lstdc++ BFS.cc -o BFS
$ g++ BFS.cc
But nothing works for me.
When I fire gcc --version
on shell. I got this:
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
The program which I was trying to run is BFS.cc
which is following:
/*
* Algo: BFS
*/
#include <iostream>
#include <list>
using namespace std;
class Graph {
int V;
list<int> *adj;
public:
Graph(int V);
void addEdge( int v, int w);
void BFS(int s);
};
Graph::Graph(int V) {
this->V = V;
adj = new list<int> [V];
}
void Graph::addEdge(int v, int w) {
adj[v].push_back(w);
}
int main(int argc, char const *argv[]) {
Graph g(4);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 0);
g.addEdge(2, 3);
g.addEdge(3, 3);
cout << "Following is Breadth First Traversal (starting from vertex 2) \n";
g.BFS(2);
return 0;
}
Can anyone help me on this?