ACE应用程序链接错误 error LNK2019 的解决办法
读者水平:初级
摘要:文本简要指出如何正确编译和链接ACE应用程序。
对于新手来说,ACE开发环境,会是一团谜团,如何正确配置开发者机器,快速体验ACE,
就是本系列文章的目的。本文仅解决如何解决LNK2019错误
环境:
ACE版本5.5.1
操作系统Windowsxpprofessionalsp2
开发环境MicrosoftVisualC++200577626-009-0000007-41235
操作系统Windowsxpprofessionalsp2
开发环境MicrosoftVisualC++200577626-009-0000007-41235
下面的代码是服务的主程序
//
@file:RegisterServer.cpp:
// @description:DefinestheentrypointfortheGameServiceDaemonapplication.
// @date:2006-07-06
// @author:Jiangtao<2005119@gmail.com>
#ifdef_DEBUG
#define ACE_NDEBUG0
#define ACE_NTRACE0
#endif
#include " stdafx.h "
#include " ACE/Filecache.h "
#include " ACE/Log_Msg.h "
#include " ACE/OS_NS_signal.h "
#include " ACE/Service_Config.h "
#ifdefACE_HAS_SIG_C_FUNC
#pragmamessage( " ACE_HAS_SIG_C_FUNC " )
extern " C "
{
#endif /*ACE_HAS_SIG_C_FUNC*/
// callexit()sothatstaticdestructorsgetcalled
static void
handler( int )
{
delete(ACE_Filecache * )ACE_Filecache::instance();
ACE_OS::exit( 0 );
}
#ifdefACE_HAS_SIG_C_FUNC
}
#endif /*ACE_HAS_SIG_C_FUNC*/
int ACE_TMAIN( int argc,ACE_TCHAR * argv[])
{
ACE_DEBUG((LM_INFO,ACE_TEXT( " 启动服务\n " )));
ACE_Service_Configdaemon;
ACE_OS::signal(SIGCHLD,SIG_IGN);
// SigActionnotneededsincethehandlerwillshutdowntheserver.
ACE_OS::signal(SIGINT,(ACE_SignalHandler)handler);
ACE_OS::signal(SIGUSR2,(ACE_SignalHandler)handler);
if (daemon.open(argc,argv,ACE_DEFAULT_LOGGER_KEY, 0 ) != 0 )
ACE_ERROR_RETURN((LM_ERROR, " %p\n " , " open " ), 1 );
// Theconfiguredservicecreatesthreads,andthe
// serverwon'texituntilthethreadsdie.
// Runforever,performingtheconfiguredservicesuntilwereceive
// aSIGINT.
return 0 ;
}
// @description:DefinestheentrypointfortheGameServiceDaemonapplication.
// @date:2006-07-06
// @author:Jiangtao<2005119@gmail.com>
#ifdef_DEBUG
#define ACE_NDEBUG0
#define ACE_NTRACE0
#endif
#include " stdafx.h "
#include " ACE/Filecache.h "
#include " ACE/Log_Msg.h "
#include " ACE/OS_NS_signal.h "
#include " ACE/Service_Config.h "
#ifdefACE_HAS_SIG_C_FUNC
#pragmamessage( " ACE_HAS_SIG_C_FUNC " )
extern " C "
{
#endif /*ACE_HAS_SIG_C_FUNC*/
// callexit()sothatstaticdestructorsgetcalled
static void
handler( int )
{
delete(ACE_Filecache * )ACE_Filecache::instance();
ACE_OS::exit( 0 );
}
#ifdefACE_HAS_SIG_C_FUNC
}
#endif /*ACE_HAS_SIG_C_FUNC*/
int ACE_TMAIN( int argc,ACE_TCHAR * argv[])
{
ACE_DEBUG((LM_INFO,ACE_TEXT( " 启动服务\n " )));
ACE_Service_Configdaemon;
ACE_OS::signal(SIGCHLD,SIG_IGN);
// SigActionnotneededsincethehandlerwillshutdowntheserver.
ACE_OS::signal(SIGINT,(ACE_SignalHandler)handler);
ACE_OS::signal(SIGUSR2,(ACE_SignalHandler)handler);
if (daemon.open(argc,argv,ACE_DEFAULT_LOGGER_KEY, 0 ) != 0 )
ACE_ERROR_RETURN((LM_ERROR, " %p\n " , " open " ), 1 );
// Theconfiguredservicecreatesthreads,andthe
// serverwon'texituntilthethreadsdie.
// Runforever,performingtheconfiguredservicesuntilwereceive
// aSIGINT.
return 0 ;
}
服务加载的配置文件
###############################################################################
#filesvc.conf
###############################################################################
dynamicGameServiceService_Object * GameService:_make_GameServer_T()active
出错提示:
-----Buildstarted:Project:RegisterServer,Configuration:DebugWin32------
Compiling
RegisterServer.cpp
Linking
RegisterServer.obj:errorLNK2019:unresolvedexternalsymbol"__declspec(dllimport)int__cdeclace_os_wmain_i(classACE_Main_Base&,int,wchar_t**const)"(__imp_?ace_os_wmain_i@@YAHAAVACE_Main_Base@@HQAPA_W@Z)referencedinfunction_wmain
RegisterServer.obj:errorLNK2019:unresolvedexternalsymbol"__declspec(dllimport)public:staticint__cdeclACE_Service_Config::open(int,wchar_t**const,wchar_tconst*,int,int,int)"(__imp_?open@ACE_Service_Config@@SAHHQAPA_WPB_WHHH@Z)referencedinfunction"int__cdeclace_wmain_i(int,wchar_t**const)"(?ace_wmain_i@@YAHHQAPA_W@Z)
D:\ACE_OUTPUT\Game\\RegisterServerd.exe:fatalerrorLNK1120:2unresolvedexternals
Buildlogwassavedat"file://d:\MySources\RegisterService\RegisterServer\Debug\BuildLog.htm"
RegisterServer-3error(s),0warning(s)
==========Build:0succeeded,1failed,1up-to-date,0skipped==========
Compiling
RegisterServer.cpp
Linking
RegisterServer.obj:errorLNK2019:unresolvedexternalsymbol"__declspec(dllimport)int__cdeclace_os_wmain_i(classACE_Main_Base&,int,wchar_t**const)"(__imp_?ace_os_wmain_i@@YAHAAVACE_Main_Base@@HQAPA_W@Z)referencedinfunction_wmain
RegisterServer.obj:errorLNK2019:unresolvedexternalsymbol"__declspec(dllimport)public:staticint__cdeclACE_Service_Config::open(int,wchar_t**const,wchar_tconst*,int,int,int)"(__imp_?open@ACE_Service_Config@@SAHHQAPA_WPB_WHHH@Z)referencedinfunction"int__cdeclace_wmain_i(int,wchar_t**const)"(?ace_wmain_i@@YAHHQAPA_W@Z)
D:\ACE_OUTPUT\Game\\RegisterServerd.exe:fatalerrorLNK1120:2unresolvedexternals
Buildlogwassavedat"file://d:\MySources\RegisterService\RegisterServer\Debug\BuildLog.htm"
RegisterServer-3error(s),0warning(s)
==========Build:0succeeded,1failed,1up-to-date,0skipped==========
问题分析
出错信息显示,不能解析函数ace_os_wmain_i()以及 ACE_Service_Config::open()。
从这里可以看出,链接器需要UNICODE版本的ace库,而我们在生成ACE的时候,并没有生成宽字符
的UNICODE版本。
解决办法:
打开项目的属性页,找到配置属性,在字符集中,选择多字节字符集。再重新编译,问题解决。