When I'm trying to link my own library to my project these errors appear:
.\main.cpp(10) : warning C4091: 'extern ' : ignored on left of 'Hamster' when no variable is declared main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Hamster::SetHealth(int)" (?SetHealth@Hamster@@QAEXH@Z) I completely don't know what to do. I have been searching for the solution on the net but without result.
(Compiled using Visual Studio C++, MS Windows XP)
Source of the static library:
struct Hamster { public: int Health; void SetHealth(int newHealth) { if(newHealth <= 100 && newHealth > 0) this->Health = newHealth; } }; Source of the console program
#include <iostream> using namespace std; #pragma comment(lib, "../Release/mylib.lib") extern struct Hamster { public: int Health; void SetHealth(int newHealth); }; void main() { Hamster White; White.SetHealth(100); cout << White.Health << endl; } Could you take a look and explain what is wrong? Thanks in advance.