0

我有一个无法解决的 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)

什么可能导致问题?

丹尼尔。

4

1 回答 1

0

基于您的新评论和您的编辑

在你的IMessageDispatcher课堂上你正在定义

 virtual ERROR_CODE SendMessage(IMessage & msg) = 0;

 virtual ERROR_CODE SendMessage(IMessage & msg, STRING destination) { 
      RAISE_AND_RETURN(EC_NOT_IMPLEMENTED); 
    };

现在INetMessageDispatcher从 IMessageDispatcher 继承这 2 个函数,这意味着在您实现纯虚拟实例后,可以在 INetMessageDispatcher 实例上调用它们。

接下来,NetMessageDispatcher继承这两个函数INetMessageDispatcher,这是一个重新定义,所以你的解决方案是

1)要么从NetMessageDispatcher类中删除重新定义,它们是不必要的

2)如果您使用 C++ 11,您可以使用override关键字

class EUROSDK_API NetMessageDispatcher : public INetMessageDispatcher
{
  ...      
  virtual ERROR_CODE SendMessage(IMessage & msg) override;
}
于 2013-10-25T12:14:51.370 回答