xcode4 - Xcode error: Undefined symbols for architecture x86_64 -
i writing template matrix class school assignment. have included error source , header files below. don't think wrong code, pretty sure reason xcode isn't recognizing header , source file. tempmlated matrix class declared in matrix.h, function definitions in matrix.cpp, , main routine in main.cpp. have included 3 files total error message xcode gives me below. i've spent lastly 2 days googling error no avail. new xcode help appreciated. if need me post more information, settings or else, don't hesitate ask. total error is:
ld /users/mikey/library/developer/xcode/deriveddata/hw3-glwfyunpxigvvpfacidnbejyprfa/build/products/debug/hw3 normal x86_64 cd /users/mikey/desktop/programming/pic10b/hw3 setenv macosx_deployment_target 10.8 /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/clang++ -arch x86_64 - isysroot /applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.8.sdk -l/users/mikey/library/developer/xcode/deriveddata/hw3-glwfyunpxigvvpfacidnbejyprfa/build/products/debug -f/users/mikey/library/developer/xcode/deriveddata/hw3-glwfyunpxigvvpfacidnbejyprfa/build/products/debug -filelist /users/mikey/library/developer/xcode/deriveddata/hw3-glwfyunpxigvvpfacidnbejyprfa/build/intermediates/hw3.build/debug/hw3.build/objects-normal/x86_64/hw3.linkfilelist -mmacosx-version-min=10.8 -stdlib=libc++ -o /users/mikey/library/developer/xcode/deriveddata/hw3-glwfyunpxigvvpfacidnbejyprfa/build/products/debug/hw3 undefined symbols architecture x86_64: "operator^(matrix<double>, int)", referenced from: _main in main.o "operator>>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, matrix<double>&)", referenced from: _main in main.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation)` //main.cpp #include<iostream> #include<vector> #include<string> #include "matrix.h" using namespace std; int main () { int numberofplanets; int steps; string planet; vector<string> planetnames; matrix<double> markovmatrix; matrix<double> stepmatrix; cout<<"please come in number of planets:"; cin>>numberofplanets; cout<<"please come in names of planets:"; for(int i=0;i<numberofplanets;i++) { cin>>planet; planetnames.push_back(planet); } cout<<"how many steps take?"; cin>>steps; cout<<"please come in "<<numberofplanets<<"x"<<numberofplanets<<" markov matrix:"; cin>>markovmatrix; stepmatrix=markovmatrix^steps; for(int i=0;i<numberofplanets;i++) { int maxentry = stepmatrix.findmax(i); cout<<"after "<<steps<<" steps, "<<planetnames[i]<<"you end @ " <<planetnames[maxentry]; cout<<endl; } homecoming 0; } //matrix.h #include<iostream> #include<iomanip> #ifndef matrix_h #define matrix_h using namespace std; template<typename t> class matrix { public: matrix(); matrix(int r, int c); ~matrix(); matrix<t>(const matrix<t>& right); matrix<t>& operator=(const matrix<t>& right); t& operator() (int i, int j); t operator() (int i, int j) const; friend ostream& operator<<(ostream& out, const matrix<t>&right); friend istream& operator>>(istream& in, matrix<t>& right); friend matrix<t> operator*(const matrix<t> left, const matrix<t> right); friend matrix<t> operator+(const matrix<t> left, const matrix<t> right); friend matrix<t> operator^(const matrix<t> right, int power); int findmax(int r) const; private: int rows; int columns; t* elements; }; #endif` //matrix.cpp #include "matrix.h" #include<iostream> #include<iomanip> using namespace std; template<typename t> matrix<t>::matrix() { rows = 0; columns = 0; elements = null; } template<typename t> matrix<t>::matrix(int r, int c) { rows = r; columns = c; elements = new t[rows*columns]; for(int i=0;i<rows*columns;i++) { elements[i]=0; } } template<typename t> matrix<t>::matrix(const matrix<t>& right) { rows = right.rows; columns = right.columns; elements = new t[rows*columns]; for(int i=0;i<rows*columns;i++) elements[i]=right.elements[i]; } template<typename t> matrix<t>& matrix<t>::operator=(const matrix<t>& right) { if(this!=&right) { rows = right.rows; columns = right.columns; delete[] elements; for(int i=0;i<rows*columns;i++) { elements[i]=right.elements[i]; } } homecoming *this; } template<typename t> t matrix<t>::operator()(int i, int j) const { homecoming elements[i*rows+j]; } template<typename t> t& matrix<t>::operator()(int i, int j) { homecoming elements[i*rows+j]; } template<typename t> matrix<t> operator+(const matrix<t>& right, const matrix<t> left) { matrix<t> a(right.rows, right.columns); for(int i=0;i<a.rows;i++) { for(int j=0;j<a.columns;j++) { a(i,j) = right(i,j)+left(i,j); } } homecoming a; } template<typename t> matrix<t> operator*(const matrix<t>& right, const matrix<t> left) { matrix<t> a(left.rows, right.columns); for(int i=0;i<left.rows;i++) { for(int j=0;j<right.columns;j++) { for(int k=0;k<right.rows;k++) { a(i,j)+=left(i,k)*right(k,j); } } } homecoming a; } template<typename t> matrix<t>::~matrix() { delete[] elements; } template<typename t> matrix<t> operator^(const matrix<t>& right, int power) { matrix<t> = right; for(int i=1;i<power;i++) a=a*right; homecoming a; } template<typename t> int matrix<t>::findmax(int r) const { int maxcolumnentry = 0; t rowmax = elements[r*columns]; for(int j=1;j<columns;j++) { if(elements[r*columns+j]>rowmax) { rowmax = elements[r*columns+j]; maxcolumnentry = j; } } homecoming maxcolumnentry; } template<typename t> ostream& operator<<(ostream& out,const matrix<t>& right) { for(int i=0;i<right.rows*right.columns;i++) { out<<setw(10)<<right.elements[i]<<" "; if((i+1)%right.columns==0) out<<endl; } homecoming out; } template<typename t> istream& operator<<(istream& in, matrix<t>& right) { for(int i=0;i<right.rows*right.columns;i++){ in>>right.elements[i]; } homecoming in; }
i believe you're compiling wrong lib. alter build settings use: compiler default in apple llvm compiler settings maybe libstdc++.
and:
project -> build settings -> find llvm compiler grouping -> c++ standard library
xcode4 clang x86-64
No comments:
Post a Comment