避免出现链接错误的一种简单处理方式
环境和平台:ACE 5.5
Visual C++ 8.0
Windows XP sp2
最近在一个项目中,用ACE开发一个可供ACE服务配置动态加载的Stream模块时,发现编译的时候,出现一个链接错误,之前也有一些人问过,大家的回答都以为是开发人员没有正确的链接ACE.lib到代码中.但实事上问题不是这样的.
下面先把出错信息复制上来
Command.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
CommandModule.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
CommandStream.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
CommandTask.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
CommandStream.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
RegistingAsynchAcceptor.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
RegistingHandler.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
ServiceFactory.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
CommandStream.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::max_time" (?max_time@ACE_Time_Value@@2V1@B)
RegistingAsynchAcceptor.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::max_time" (?max_time@ACE_Time_Value@@2V1@B)
RegistingHandler.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::max_time" (?max_time@ACE_Time_Value@@2V1@B)
ServiceFactory.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::max_time" (?max_time@ACE_Time_Value@@2V1@B)
RegistingAsynchAcceptor.obj : error LNK2001: unresolved external symbol "public: static class ACE_Addr const ACE_Addr::sap_any" (?sap_any@ACE_Addr@@2V1@B)
RegistingHandler.obj : error LNK2001: unresolved external symbol "public: static class ACE_Addr const ACE_Addr::sap_any" (?sap_any@ACE_Addr@@2V1@B)
ServiceFactory.obj : error LNK2019: unresolved external symbol "public: static class ACE_Addr const ACE_Addr::sap_any" (?sap_any@ACE_Addr@@2V1@B) referenced in function "public: void __thiscall RegistingAsynchAcceptor_T::`default constructor closure'(void)" (??_FRegistingAsynchAcceptor_T@@QAEXXZ)
D:\ACE_wrappers\lib\ServiceFactoryd.dll : fatal error LNK1120: 4 unresolved externals
大家可以看到,链接出错,仅限于ACE的几个基础类
解决办法我暂时发现两种:
方法一:把这些类的*.cpp文件引入到项目中,这可以通过mpc来做.
另一种办法更简单,下面这样
//避免出现链接错误的一种方法
#include "ace/Addr.cpp"
#include "ace/Time_Value.cpp"
#include "ace/String_Base_Const.cpp"
#include "ace/OS_String.cpp"
但这两种方法,都显得很不优雅.不知道你有什么更好的办法? 可能是ACE_Export 这个宏没有正确的展开还是什么原因的 找到正确展开宏的预编译指令在MPC中的解:
dynamicflags += ACE_BUILD_SVC_DLL
页:
[1]