我有一个无法解决的 LNK2001 错误!
我的解决方案由一个本地项目 (DLL) 和一个托管项目(DLL 包装器)组成。
如果与本机测试应用程序一起使用,本机 DLL 可以工作。
现在,本机代码如下(全部定义在命名空间 EuroSDK::Protocols 中):
EUROSDK_API 定义为 __declspec(dllexport)
IMessageDispatcher.h
class EUROSDK_API IMessageDispatcher {
public:
IMessageDispatcher() : m_ProtocolAdapter(0) {};
virtual ~IMessageDispatcher() {};
virtual ERROR_CODE SendMessage(IMessage & msg) = 0;
virtual ERROR_CODE SendMessage(IMessage & msg, STRING destination) {
RAISE_AND_RETURN(EC_NOT_IMPLEMENTED);
};
virtual ERROR_CODE SendMessageSync(IMessage & msg) {
RAISE_AND_RETURN(EC_NOT_IMPLEMENTED);
};
virtual ERROR_CODE SendMessageSync(IMessage & msg, IMessage & ret_msg) {
RAISE_AND_RETURN(EC_NOT_IMPLEMENTED);
};
virtual ERROR_CODE SendMessageRaw(char* buff, UINT size) {
RAISE_AND_RETURN(EC_NOT_IMPLEMENTED);
};
ERROR_CODE SetProtocolAdapter(IProtocolAdapter * adapter) {
m_ProtocolAdapter = adapter;
return EC_NO_ERRORS;
}
protected:
IProtocolAdapter* m_ProtocolAdapter;
};
class EUROSDK_API INetMessageDispatcher : public IMessageDispatcher {
public:
virtual ERROR_CODE Init(STRING stationName,
STRING userName,
BOOL crypthData = FALSE) = 0;
virtual ERROR_CODE Connect(UINT portNumber,
STRING remoteIP,
UINT connectionTimeOut = 5000) = 0;
virtual ERROR_CODE Disconnect() = 0;
};
NetMessageDispatcher.h
class EUROSDK_API NetMessageDispatcher : public INetMessageDispatcher
{
...
ERROR_CODE SendMessage(IMessage & msg);
ERROR_CODE SendMessage(IMessage & msg, STRING destination);
...
};
NetMessageDispatcher.cpp
ERROR_CODE NetMessageDispatcher::SendMessage(IMessage & msg) {
... implementation ...
}
ERROR_CODE NetMessageDispatcher::SendMessage(IMessage & msg, STRING destination) {
... implementation ...
}
现在,进入托管包装器,我有:
NetMessageDispatcherNET.h
using namespace EurocSDK::Protocols;
namespace EuroSDKNET {
namespace Protocols {
class NetMessageDispatcherWrap;
public ref class NetMessageDispatcherNET {
public:
NetMessageDispatcherNET(EDispatcherType stationType,
MessageEventHandlerNET^ handler)
~NetMessageDispatcherNET() {};
// Implemented in the cpp file
virtual int SendMessage(IMessageNET^ msg);
virtual int SendMessage(IMessageNET^ msg, String^ destination);
private:
CAutoNativePtr<NetMessageDispatcherWrap> m_Dispatcher;
};
// Unmanaged Wrapper
private class NetMessageDispatcherWrap : public ISessionFactory,
public NetMessageDispatcher {
public:
~NetMessageDispatcherWrap() {}
NetMessageDispatcherWrap(MessageEventHandlerNET^ handler,
NetMessageDispatcherNET^ dispatcher,
IMessageFactory::Ptr messageFactory,
EuroSDKNET::Protocols::EDispatcherType stationType) :
NetMessageDispatcher(this,
messageFactory,
Logger::get("NetMessageDispatcher"),
(EuroSDK::Protocols::EDispatcherType)stationType),
m_handler(handler),
m_Dispatcher(dispatcher) {}
/// Creates an instance of a Session,
/// using the given message handler.
inline Session* createSession(const IMessageDispatcher* dispatcher) {
..... implementation ....
}
private:
gcroot<MessageEventHandlerNET^> m_handler;
gcroot<NetMessageDispatcherNET^> m_Dispatcher;
};
}
}
NetMessageDispatcherNET.cpp
NetMessageDispatcherNET::NetMessageDispatcherNET(EuroSDKNET::Protocols::EDispatcherType stationType,
MessageEventHandlerNET^ handler) {
m_Dispatcher = new NetMessageDispatcherWrap(handler,
this,
new EuroSDK::Protocols::PBMessageFactory(),
stationType);
}
NetMessageDispatcherNET::~NetMessageDispatcherNET() {}
int NetMessageDispatcherNET::SendMessage(IMessageNET^ msg) {
return 0;
}
int NetMessageDispatcherNET::SendMessage(IMessageNET^ msg, String^ destination) {
return 0;
}
现在,当我构建 NET DLL 时,我得到:
1>NetMessageDispatcher.obj : warning LNK4248: unresolved typeref token (01000017) for 'boost.detail.win32._SECURITY_ATTRIBUTES'; image may not run
1>NetMessageDispatcherWrapper.obj : error LNK2001: unresolved external symbol "public: virtual enum E_ErrorCode __thiscall EuroSDK::Protocols::NetMessageDispatcher::SendMessage(class EuroSDK::Protocols::IMessage &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?SendMessage@NetMessageDispatcher@Protocols@EuroSDK@@UAE?AW4E_ErrorCode@@AAVIMessage@23@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>NetMessageDispatcherWrapper.obj : error LNK2001: unresolved external symbol "public: virtual enum E_ErrorCode __thiscall EuroSDK::Protocols::NetMessageDispatcher::SendMessage(class EuroSDK::Protocols::IMessage &)" (?SendMessage@NetMessageDispatcher@Protocols@EuroSDK@@UAE?AW4E_ErrorCode@@AAVIMessage@23@@Z)
什么可能导致问题?
丹尼尔。