I am trying to create a static library that I will use in a project. The library compiles and creates a * .lib file for it. To test my code, I added another project to the same solution. When I try to build a test project, I get the following errors.
error LNK1120: 4 unresolved external
LNK2019 error: unresolved external symbol "public: __thiscall> matrix :: ~ matrix (void)" (? 1? $ matrix @M @@ QAE @XZ) referenced by the _main function
LNK2019 error: unresolved external symbol "public: __thiscall> matrix :: matrix> (int, int)" (? 0? $ matrix @M @@ QAE @HH @Z), which is referenced by the function> _main C: \ Users \ Ryan \ Documents \ Spring 2013 \ ECE> 4007 \ PointCloudLib \ matrix_test \ matrix_test.obj matrix_test
error LNK2019: unresolved external symbol "public: bool __thiscall> matrix :: set (int, int, float)" (? set @? $ matrix @M @@ QAE_NHHM @Z) function link> _main
error LNK2019: unresolved external symbol "public: static void __cdecl> matrix :: print (class matrix const &)" (? print @? $ matrix @M @@ SAXABV1 @@ Z)> link in _main function
To use the library in my code, I followed these steps:
- Added link to the static library by going to the links ...> Add a new link .. and selecting my library
- A directory has been added in which the source files to include directories using configuration properties> C / C ++> General> Additional Include directories (I feel that this is not necessary, as this creates the purpose of creating a library)
These are the steps listed on the Microsoft msdn website about creating your own static libraries, and it seems like what other people are saying is a solution to the problem.
Is there anything else I need to do to use the library in my project?
Also, here is the code I use to test the library:
#pragma once #include "stdafx.h" #include <iostream> #include "matrix.h" #define PI 3.14 #define matrix_f matrix<float> int main() { matrix_f m(3,4); for(int i = 0; i < 3; i++) for(int j = 0; j < 4; j++) m.set(i,j,PI/((i+1)*(j+1))); matrix_f::print(m); }