Author Topic: Creating static library than linking  (Read 3084 times)

csiz

  • Guest
Creating static library than linking
« on: November 08, 2009, 09:05:33 pm »
I've been trying for a while to make a library static, than use it in another project but I haven't been successful.

What I did: made a static library project, added my files and compiled
made an empty project and wrote the test program
took the libmatrix.a from the static library folder and put it in test
add files to test project, added libmatrix.a in linker options, test folder to search directories-linker
and compiled

But I get these error:
Code
||=== test, Release ===|
obj\Release\test.o||In function `main':|
C:\Users\Admin\Desktop\test\test.cpp|6|undefined reference to `matrix<5, 5, int>::matrix(int)'|
C:\Users\Admin\Desktop\test\test.cpp|7|undefined reference to `matrix<5, 5, int>::write(std::ostream&)'|
C:\Users\Admin\Desktop\test\test.cpp|8|undefined reference to `matrix<3, 3, int>::matrix(int)'|
C:\Users\Admin\Desktop\test\test.cpp|9|undefined reference to `matrix<3, 3, int>::write(std::ostream&)'|
||=== Build finished: 4 errors, 0 warnings ===|

What I don't get is why are the definitions missing if I have:
Code
template<int X,int Y,class T>
matrix<X,Y,T>::matrix(int x){
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            m[i][j]=T(0);
        }
    }
    if(X==Y){
        for(int i=0;i<X;i++){
            m[i][i]=x;
        }
    }
}
and the other 2 functions in the matrix.cpp file that I added and compiled in the static library project

here are the 2 projects http://www.mediafire.com/?jamtzhryymy , i believe you will have to change the folder in search directory-linker

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Creating static library than linking
« Reply #1 on: November 08, 2009, 11:23:07 pm »
Not related to C::B in any way, thus violating our forum rules.

Topic locked !

A tip: search for "static lib template" with google gives you the answer, why it can not work.