-1

A project consists of the following class (further functions are omitted):

// MyClass.h
class MyClass {
    public:
        virtual void print();
};

// MyClass.cpp 
#include "stdafx.h"
#include "MyClass.h"
void MyClass::print() {
    // empty
}

In ANOTHER project a class is derived from MyClass. The print function is not overwritten. In the linking step after the compilation a definition of the function print can't be found ("unresolved external symbol" error). How can I fix this issue? The project with the MyClass.h and MyClass.cpp is referenced in the project.

Edit: Development Environment is VS 2015 on Win10 x64. If I remove the keyword virtual or move MyClass.h and MyClass.cpp to the other project the error doesn't occur anymore.

Edit 2: Both projects are dynamic libraries (DLLs).

user1056903
  • 921
  • 9
  • 26
  • Guess you're not linking your cpp files correctly. Duplicate of http://stackoverflow.com/questions/9928238/unresolved-external-symbol-in-object-files – UKMonkey Oct 21 '16 at 15:48
  • 2
    What is your environment? UNIX/Linux/Mac/VS/Something else? – Sergey Kalinichenko Oct 21 '16 at 15:48
  • What is your development environment? How is your setup? How does MySubClass look like? Your example is unfortunately neither minimal nor working... It is not easy to help that way. – Ely Oct 21 '16 at 16:00
  • 1
    @UKMonkey This is the more complete duplicate: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – πάντα ῥεῖ Oct 21 '16 at 16:51

1 Answers1

0

The project containing MyClass.cpp will generate a .lib file when it is built. That library file must be added to the other project so that it can be linked in, telling that project that it can find the code in the other DLL.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • The directory with the lib is added at "Additional Library Directories" and the lib itself at "Additional Dependencies" in the project properties. – user1056903 Oct 21 '16 at 21:08
  • @user1056903 I'm not sure that simply adding it to the project properties dependencies is enough. Unfortunately it isn't anything I've had to do myself lately so I don't have a specific step to follow. – Mark Ransom Oct 21 '16 at 21:10