找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 5673|回复: 2

避免出现链接错误的一种简单处理方式

[复制链接]
发表于 2007-12-28 23:37:52 | 显示全部楼层 |阅读模式
环境和平台:

ACE 5.5

Visual C++ 8.0

Windows XP sp2

最近在一个项目中,用ACE开发一个可供ACE服务配置动态加载的Stream模块时,发现编译的时候,出现一个链接错误,之前也有一些人问过,大家的回答都以为是开发人员没有正确的链接ACE.lib到代码中.但实事上问题不是这样的.

下面先把出错信息复制上来

  1. Command.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
  2. CommandModule.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
  3. CommandStream.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
  4. CommandTask.obj : error LNK2001: unresolved external symbol "public: static int const ACE_String_Base_Const::npos" (?npos@ACE_String_Base_Const@@2HB)
  5. CommandStream.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
  6. RegistingAsynchAcceptor.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
  7. RegistingHandler.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
  8. ServiceFactory.obj : error LNK2001: unresolved external symbol "public: static class ACE_Time_Value const ACE_Time_Value::zero" (?zero@ACE_Time_Value@@2V1@B)
  9. 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)
  10. 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)
  11. 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)
  12. 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)
  13. RegistingAsynchAcceptor.obj : error LNK2001: unresolved external symbol "public: static class ACE_Addr const ACE_Addr::sap_any" (?sap_any@ACE_Addr@@2V1@B)
  14. RegistingHandler.obj : error LNK2001: unresolved external symbol "public: static class ACE_Addr const ACE_Addr::sap_any" (?sap_any@ACE_Addr@@2V1@B)
  15. 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)
  16. 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"


但这两种方法,都显得很不优雅.不知道你有什么更好的办法?
 楼主| 发表于 2007-12-28 23:38:01 | 显示全部楼层
可能是ACE_Export 这个宏没有正确的展开还是什么原因的
 楼主| 发表于 2007-12-28 23:38:07 | 显示全部楼层
找到正确展开宏的预编译指令在MPC中的解:

dynamicflags += ACE_BUILD_SVC_DLL
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-12-23 03:19 , Processed in 0.016733 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表