I'm new to managed C++.
I have two managed C++ projects in a single .sln, Project Lib and Project LibTest. LibTest makes use of Lib.
Lib compiles and links fine. The project is set as a .dll.
LibTest is also compiled as .dll, but when it goes into linking, I get "unresolved token" on all of the Lib::methods. Those methods definitions are defined in the Lib .cpp file.
If I moved the definitions into the Lib.h file, everything works.
I have already modified LibTest's Reference to depend on Lib project.
What am I missing?
EDIT: Okay here's exactly what I have and it still doesn't work.
First off, I'm using Visual Studio 2008 SP1.
Secondly, when I did a similar exercise in C#, it worked fine.
I created an empty C++ CLR project. I added a Lib project. I added a managed class. VSTD generated Lib.h and Lib.cpp. The constructor is automatically generated.
Then I added another project to my solution; I called it LibTest. I added another managed class called LibTest. LibTest.h and LibTest.cpp are generated. I tried to instantiate Lib in LibTest constructor, but during linking it simply said:
1>LibTest.obj : error LNK2020: unresolved token (06000002) Lib::.ctor
Here's the exact code:
Lib Project (compiled as .dll project)
//Lib.h
#pragma once
ref class Lib
{
public:
Lib(void);
};
//Lib.cpp
#include "Lib.h"
Lib::Lib(void)
{
}
LibTest Project (compiled as application.exe)
// LibTest.h
#pragma once
ref class LibTest
{
public:
LibTest(void);
};
// LibTest.cpp
#include "LibTest.h"
#include "Lib.h"
LibTest::LibTest(void)
{
Lib^ lib = gcnew Lib;
}
int main()
{
return 0;
}