Unresolved external symbol这种错误应该在哪里解决
编号:QA004155
建立日期: 2001年4月25日 最后修改日期:2001年4月25日
所属类别:
周俊:
我最近在编程时又遇到了一个问题,就是在程序的编译过程中,当link时总实体是错误,不知道该如何解决。unresolved external symbol这种错误应该在那里解决?程序及错误如下:
// reg.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "reg.h"
#include "assert.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
void analyze_string( CString *string ); /* Prototype */
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CListBox documentdoc;
CString mydir;
CString *mydirde='\0';
*mydirde=mydir.LoadString(IDS_mydir);
printf ( "Analyzing string '%s'\n", mydir );
analyze_string( mydirde );
documentdoc.Dir(0x0000,mydir);
int I=documentdoc.GetCount();
cout << I << endl;
CString mykey;
mykey.LoadString(IDS_mykey);
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
return nRetCode;
}
void analyze_string( CString string )
{
assert( string != NULL ); /* Cannot be NULL */
// assert( *string != '\0' ); /* Cannot be empty */
assert( strlen( string ) > 2 ); /* Length must exceed 2 */
}
Deleting intermediate files and output files for project 'reg - Win32 Debug'.
--------------------Configuration: reg - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
reg.cpp
Linking...
reg.obj : error LNK2001: unresolved external symbol "void __cdecl analyze_string(class CString *)" (?analyze_string@@YAXPAVCString@@@Z)
Debug/reg.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
reg.exe - 2 error(s), 0 warning(s)
回答:
在QA000267 "Error LNK2001:unresolved external symbol",我们已经介绍了这种错误的一般处理方法,但是你的问题和那里介绍的不一样。你在定义原形时,analyze_string的参数是指针,在调用的时候使用的也是指针,但是在实现analyze_string时,使用的却是非指针形式。
此问题由李海回答。
| |
|
|
| |
|
|