f1.cpp file contains the code for two simple classes. Class A has the function print() defined inside, class B has the function defined outside.
class A{
public:
void print(){}
};
class B{
public:
void print();
};
void B::print(){
}
f1.cpp will generate f1.lib.
f2.cpp contains the header for the two classes and the main() function (and it will link with f1.lib to create f2.exe):
class A{
public:
void print();
};
class B{
public:
void print();
};
int main(){
A a;
a.print();
B b;
b.print();
}
When I compile (in Visual Studio 2019), I get a linking error only for class A:
error LNK2001: unresolved external symbol "public: void __thiscall A::print(void)" (?print@A@@QAEXXZ)
fatal error LNK1120: 1 unresolved externals
It seems that the A::print function is not present as a symbol in the lib.
Initially I thought that is because an internal function definition becomes "inline" by default. But I've tried adding the __declspec(noinline) attribute in front of it and it is still not working.
Do you know why the symbol is not present?