出现这个错误网上也有很多现象,比如工程建立的不对,一些库的导出问题,或者某某函数没有实现等等,网上也有很多有效的解决办法。
我也遇到了这个问题:程序是一个多线程程序,Debug版本没有问题,Release(多线程Use run-time library要用Multithreaded)静态库编译出现以下链接问题。
Linking...
MainFrm.obj : error LNK2001: unresolved external symbol "protected: long __thiscall CMainFrame::OnMessage(unsigned int,long)" (?OnMessage@CMainFrame@@IAEJIJ@Z)
MainFrm.obj : error LNK2001: unresolved external symbol "public: void __thiscall CMainFrame::WriteLog(class CString)" (?WriteLog@CMainFrame@@QAEXVCString@@@Z)
MainFrm.obj : error LNK2001: unresolved external symbol "public: static unsigned int __cdecl CMainFrame::WatchThread(void *)" (?WatchThread@CMainFrame@@SAIPAX@Z)
MainFrm.obj : error LNK2001: unresolved external symbol "public: void __thiscall CMainFrame::AutoStart(void)" (?AutoStart@CMainFrame@@QAEXXZ)
Release/INMSWatch.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
发现也不是网上常见的那几种错误啊。
/
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
UINT CMainFrame::WatchThread(LPVOID pParam)
{
}
LRESULT CMainFrame::OnMessage(WPARAM wparam,LPARAM lparam)
{
}
void CMainFrame::ExitINMSMProcess()
{
}
///开机自启动
void CMainFrame::AutoStart()
{
}
void CMainFrame::WriteLog(CString strLogInfo)
{
}
#endif //_DEBUG
原来自己添加的函数写的地方不对。
如下:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
if(cs.hMenu!=NULL) //去除菜单栏
{
::DestroyMenu(cs.hMenu); // delete menu if loaded
cs.hMenu = NULL; // no menu for this window
}
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
/
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
UINT CMainFrame::WatchThread(LPVOID pParam)
{
}
LRESULT CMainFrame::OnMessage(WPARAM wparam,LPARAM lparam)
{
}
void CMainFrame::WriteLog(CString strLogInfo)
{
}
其中WatchThread为线程函数,OnMessage为自定义消息,WriteLog为自己添加的函数,放到了#endif里面就出现了这几个链接错误,所以最好用vc提供的添加函数工具来写,不容易出现错误。