找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 5051|回复: 2

ACE Programmer's Guid中的7.6.3 demo出现link 错误

[复制链接]
发表于 2007-12-21 22:03:59 | 显示全部楼层 |阅读模式
Linking...
   Creating library G:\test\ace_client\Debug\ace_client.lib and object G:\test\ace_client\Debug\ace_client.exp
maintian.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ace_os_wmain_i(class ACE_Main_Base &,int,wchar_t * * const)" (__imp_?ace_os_wmain_i@@YAHAAVACE_Main_Base@@HQAPA_W@Z) referenced in function _wmain
maintian.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl __ace_assert(char const *,int,wchar_t const *)" (__imp_?__ace_assert@@YAXPBDHPB_W@Z) referenced in function "public: static void * __cdecl ACE_Svc_Handler<class ACE_SOCK_Stream,class ACE_NULL_SYNCH>::operator new(unsigned int,struct std::nothrow_t const &)" (??2?$ACE_Svc_Handler@VACE_SOCK_Stream@@VACE_NULL_SYNCH@@@@SAPAXIABUnothrow_t@std@@@Z)
G:\test\ace_client\Debug\ace_client.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://g:\test\ace_client\ace_client\Debug\BuildLog.htm"
ace_client - 3 error(s), 0 warning(s)

在编译ACE Programmer's Guid中的7.6.3 Using ACE_Connector, and Other Features中的 Client主动连接出现错误

程序码如下:
  1. #include"ace/Reactor.h"
  2. #include"ace/INET_Addr.h"
  3. #include"ace/SOCK_Stream.h"
  4. #include"ace/SOCK_Connector.h"
  5. #include"ace/Connector.h"
  6. #include"ace/Svc_Handler.h"
  7. #include"ace/Reactor_Notification_Strategy.h"
  8. #include <ace/Null_Mutex.h>/////////
  9. #include "ace/Message_Queue.h"
  10. #include "ace/Timer_Queue.h"
  11. #include "ace/Null_Mutex.h"
  12. #include "ace/Null_Condition.h"
  13. #include "ace/Synch.h"///////
  14. #include "ace/Message_Block.h"
  15. #include"ace/OS.h"
  16. class Client :
  17.     public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
  18. {
  19.   typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> super;
  20. public:
  21.   Client () : notifier_ (0, this, ACE_Event_Handler::WRITE_MASK)
  22.       {}
  23.   virtual int open (void * = 0);
  24.   // Called when input is available from the client.
  25.   virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
  26.   // Called when output is possible.
  27.   virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);
  28.   // Called when a timer expires.
  29.   virtual int handle_timeout (const ACE_Time_Value &current_time,
  30.                               const void *act = 0);
  31. private:
  32.   enum { ITERATIONS = 5 };
  33.   int iterations_;
  34.   ACE_Reactor_Notification_Strategy notifier_;
  35. };
  36. ///////////////////////////////////////////////cient.cpp////////////////////////////////////////////////////
  37. #include"client.h"
  38. int Client::open(void * p)
  39. {
  40. ACE_Time_Value iter_delay(2);
  41. if(super::open(p)==-1)
  42.   return -1;
  43. this->notifier_.reactor(this->reactor());
  44. this->msg_queue()->notification_strategy(&this->notifier_);
  45. return this->reactor()->schedule_timer(this,0,ACE_Time_Value::zero,iter_delay);
  46. }
  47. int Client::handle_input(ACE_HANDLE)
  48. {
  49. char buf[64];
  50. ssize_t recv_cnt=this->peer().recv(buf,sizeof(buf)-1);
  51. if(recv_cnt>0)
  52. {
  53.   ACE_DEBUG((LM_DEBUG,ACE_TEXT("%*C"),ACE_static_cast(int,recv_cnt),buf));
  54.   return 0;
  55. }
  56. if(recv_cnt==0||ACE_OS::last_error()!=EWOULDBLOCK)
  57. {
  58.   this->reactor()->end_reactor_event_loop();
  59.   return -1;
  60. }
  61. return 0;
  62. }
  63. int Client::handle_output(ACE_HANDLE)
  64. {
  65. ACE_Message_Block *mb;
  66. ACE_Time_Value nowait(ACE_OS::gettimeofday());
  67. while(-1!=this->getq(mb,&nowait))
  68. {
  69.   ssize_t send_cnt=this->peer().send(mb->rd_ptr(),mb->length());
  70.   if(send_cnt==-1) {}
  71.   else mb->rd_ptr(ACE_static_cast(size_t,send_cnt));
  72.   if(mb->length()>0)
  73.   {
  74.    this->ungetq(mb);
  75.    break;
  76.   }
  77.   mb->release();
  78. }
  79. if(this->msg_queue()->is_empty())
  80.   this->reactor()->cancel_wakeup(this,ACE_Event_Handler::WRITE_MASK);
  81. else this->reactor()->schedule_wakeup(this,ACE_Event_Handler::WRITE_MASK);
  82. return 0;
  83. }
  84. int Client::handle_timeout(const ACE_Time_Value&, const void*)
  85. {
  86. if(this->iterations_>=ITERATIONS)
  87. {
  88.   this->peer().close_writer();
  89.   return 0;
  90. }
  91. ACE_Message_Block *mb;
  92. char msg[128];
  93. ACE_OS::sprintf (msg, "Iteration %d\n", this->iterations_);
  94. ACE_NEW_RETURN (mb, ACE_Message_Block (msg), -1);
  95. this->putq (mb);
  96. return 0;
  97. }
  98. ////////////////////////////////////////////////////////////////maintian.cpp////////////////////
  99. #include"client.h"
  100. int ACE_TMAIN (int, ACE_TCHAR *[])
  101. {
  102. ACE_INET_Addr port_to_connect ("192.168.2.56:5000");
  103. ACE_Connector<Client, ACE_SOCK_CONNECTOR> connector;
  104. Client client;
  105. Client *pc = &client;
  106. if (connector.connect (pc, port_to_connect) == -1)
  107.     ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
  108.                        ACE_TEXT ("connect")), 1);
  109. ACE_Reactor::instance ()->run_reactor_event_loop ();
  110. return (0);
  111. }
复制代码
 楼主| 发表于 2007-12-21 22:04:07 | 显示全部楼层
最后通过

property pages

configuration properties /general /project  defaults character set 改为not set

程序总算正常运作了
 楼主| 发表于 2007-12-21 22:04:12 | 显示全部楼层
字符集差异,lib必须和主工程保持一致。
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

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

GMT+8, 2024-11-23 15:49 , Processed in 0.014634 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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