Link error in a C++/CLI application linking a static C++/CLI library
I have a static C++/CLI library in which the following class is defined:
ObjectWrapper.h:
public ref class CObjectWrapper: System::Object
{
public:
CObjectWrapper(CObject& wrappedObject);
explicit operator CObject*();
private:
CObject& m_WrappedObject;
};
ObjectWrapper.cpp:
#include "stdafx.h"
#include "BasicObjectWrapper.h"
CObjectWrapper::CObjectWrapper(CObject& wrappedObject)
: WrappedObject(wrappedObject)
{ }
CObjectWrapper::operator CObject*()
{
return &WrappedObject;
}
I have a C++/CLI application which is linked to the stat开发者_JS百科ic library. The following errors arise at link:
Error 3 error LNK2020: unresolved token (06000007)
CObjectWrapper::.ctor
KCBrowserInEcrinView.objError 4 error LNK2020: unresolved token (06000005)
CObjectWrapper::.ctor
KCBrowserLibD9.libError 5 error LNK2020: unresolved token (06000008)
CObjectWrapper::op_Implicit
KCBrowserInEcrinView.objError 6 error LNK2020: unresolved token (06000006)
CObjectWrapper::op_Implicit
KCBrowserLibD9.lib
I solved the problem by moving the implementation (previously located in the .cpp file) to the .h file. I don't understand why.
I would highly appreciate if anybody could bring any explication.
精彩评论