Today I wanted to make my own dynamic library. I am using VC++ 2010. Tried to apply a console example (from http://msdn.microsoft.com/en-us/library/ms235636%28v=vs.80%29.aspx) but I keep failing. Here are steps I follow:
- Create Win32 project and choose Empty Project, DLL from wizard,
Create a header with
// FILE: bday.h #ifndef BDAY_H_ #define BDAY_H_ #ifdef BUILD_DLL #define PORT_DLL __declspec(dllexport) #else #define PORT_DLL __declspec(dllimport) #endif namespace Tests { public class BDay { public: static PORT_DLL double Foo(double); }; }; #endif- Create a .cpp to implement that class,
- Build this project which is successful.
Then I go with
- Create Windows Forms project, add reference to the previously created .dll,
- Include bday.h from the previous project.
- Define BUILD_DLL constant,
- Add a button which calls Tests::BDay::Foo upon clicking.
Building this project gives me
1>CoreResGen:
1> Processing resource file "Form1.resX" into "Debug\generatory2.Form1.resources".
1>generatory2.obj : error LNK2028: unresolved token (0A00000F) "public: static double __cdecl Tests::BDay::Foo(double)" (?Foo@BDay@Tests@@$$FSANN@Z) referenced in function "private: void __clrcall generatory2::Form1::button4_Click(class System::Object ^,class System::EventArgs ^)" (?button4_Click@Form1@generatory2@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>generatory2.obj : error LNK2019: unresolved external symbol "public: static double __cdecl Tests::BDay::Foo(double)" (?Foo@BDay@Tests@@$$FSANN@Z) referenced in function "private: void __clrcall generatory2::Form1::button4_Click(class System::Object ^,class System::EventArgs ^)" (?button4_Click@Form1@generatory2@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>C:\Users\Patryk\Documents\Visual Studio 2010\Projects\generatory2\Debug\generatory2.exe : fatal error LNK1120: 2 unresolved externals
There must me something that I'm doing wrong, can you point out where the error is?