Trying to create Library in C++. Test project can't find implementation of declared constructor? -


i'm learning c++, hit plateau trying create library. using visual studio 2013, error:

error 1 error lnk2019: unresolved external symbol "public: __thiscall polynomial::polynomial(void)" (??0polynomial@@qae@xz) referenced in function _main a:\medier\desktop\polylib\test\test.obj test

the testproject cut down this:

#include "a:\medier\desktop\polylib\polylib\polylib.h"  using namespace std;  void main() {     polynomial poly; } 

the library header file, polylib.h, looks this:

using namespace std;  class polynomial {  private:     double* coefficients;  //array of coefficients - pointer type.     int degree; //the highest exponent of polynomial  public:     polynomial(); //default constructor - creates trivial polynomial 0.     polynomial(int degree, double coefficients[]); //constructor specific polynomials 

finally there's cpp file in library, polylib.cpp, providing implementations header file. looks this:

#include "polylib.h"  using namespace std;  polynomial::polynomial() {     degree = 0;     coefficients = new double[degree + 1];     coefficients[0] = 0; }  polynomial::polynomial(int degree, double coefficients[]) : degree(degree), coefficients(coefficients) {     int = 0; 

}

i understand test project looks polylib.h file see stuff available. , understand error says can't find actual implementation of empty constructor polynomial. such conclude polylib.cpp file not being used.

can tell me go here?

it possible build of .cpps single project, common beginners. however, question tags , wording, i'm assuming want create , link static lib, can done simply.

i constructed example of set static lib + exe linking in 1 vs2013 project: dropbox link, purposes of explaining question.

the basics need 2 projects: lib project (outputs static .lib file) , exe project (outputs .exe file). .exe project contains main() function, , able include headers , link .lib.

the points of interest in myexe added $(solutiondir)\libexample\inc include path in order include header (header.h), , added $(solutiondir)\$(configuration) lib path libraries. can find these right clicking project, go properties, , it's under "vc++ directories".

a great tip determining path needed find lib build lib. tells in "output->build" text spew file built located. path need. $(solutiondir)\$(configuration) "macro" shorthand of path. recommend using macros can move project directory path or computer easily.

i added libexample.lib; "additional dependencies" in linker\input settings. key step being able link lib. not doing result in unresolved external symbol, you're seeing.

i set dependency between myexe , libexample (you right click project, build dependencies->project dependencies). important can rebuild entire solution without worry of linking older version of lib. dependency in place, build lib first, exe.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -