0

I've 3 projects in my solution: Project_I, Project_A, Project_B

Project_I contains header files only (no cpp), this projects defines interfaces in the header files that Project_A and Projects_B derive from and implement.

Since I want default behavior in Project_I interfaces methods to throw NOT_IMPLEMENTED_EXCEPTION (my std::exception subtype), for each method declared in any of Project_I interfaces (header files) I wrote the this implementation in the header files, Also I implemented the C'TORs in the header files.

Now, when I try to compile the solution (after defining the project dependencies and etc...) I get the following error

Error   1   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl Project_I::ClassA::ClassA()" referenced in function "public: __cdecl Project_B::ClassA_1::ClassA_1 K:\src\Project_B\ClassA_1.obj

Why does the VC++ compiler looks for the .obj file of ClassA in project_I (which needs to be built afterward) if there is no cpp file at all (the whole implementation is in the header file)?

ptCoder
  • 2,229
  • 3
  • 24
  • 38
Hawk89
  • 233
  • 1
  • 2
  • 12
  • Have you declared your class in Project_I as a __declspec(dllexport)? – Paolo M Apr 28 '15 at 15:31
  • Still better... paste declaration and definition of Project_I::ClassA, please. – Paolo M Apr 28 '15 at 15:33
  • Yes, Project_I declared as __declspec(dllexport) because all the projects compile to dlls. Here is Project_I classA declaration & definition header (no cpp file): namespace project_i { //! Histogram class. /*! Image histogram calculator interface class */ class PROJECT_I_API ClassA { public: virtual void Do_Something() { THROW_ERROR(IPM_NOT_SUPPORTED, "Operation is not implemented."); } /*! Default C'TOR */ ClassA(int& _num) : m_num(_num) {} /*! Virtual D'TOR of the object */ virtual ~ClassA(){} protected: int& m_num; }; } – Hawk89 Apr 29 '15 at 06:04

1 Answers1

2

If your Project_I::ClassA is implemented into a header file, it will not be compiled at all into the dll (unless the header is included by some cpp file of Project_I, of course).

So, you have two options: create a cpp file and include the header containing ClassA definition or remove any __declspec declaration from it.

Paolo M
  • 12,403
  • 6
  • 52
  • 73