ACE Programmer's Guid中的7.6.3 demo出现link 错误
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主动连接出现错误
程序码如下:
#include"ace/Reactor.h"
#include"ace/INET_Addr.h"
#include"ace/SOCK_Stream.h"
#include"ace/SOCK_Connector.h"
#include"ace/Connector.h"
#include"ace/Svc_Handler.h"
#include"ace/Reactor_Notification_Strategy.h"
#include <ace/Null_Mutex.h>/////////
#include "ace/Message_Queue.h"
#include "ace/Timer_Queue.h"
#include "ace/Null_Mutex.h"
#include "ace/Null_Condition.h"
#include "ace/Synch.h"///////
#include "ace/Message_Block.h"
#include"ace/OS.h"
class Client :
public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> super;
public:
Client () : notifier_ (0, this, ACE_Event_Handler::WRITE_MASK)
{}
virtual int open (void * = 0);
// Called when input is available from the client.
virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
// Called when output is possible.
virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);
// Called when a timer expires.
virtual int handle_timeout (const ACE_Time_Value ¤t_time,
const void *act = 0);
private:
enum { ITERATIONS = 5 };
int iterations_;
ACE_Reactor_Notification_Strategy notifier_;
};
///////////////////////////////////////////////cient.cpp////////////////////////////////////////////////////
#include"client.h"
int Client::open(void * p)
{
ACE_Time_Value iter_delay(2);
if(super::open(p)==-1)
return -1;
this->notifier_.reactor(this->reactor());
this->msg_queue()->notification_strategy(&this->notifier_);
return this->reactor()->schedule_timer(this,0,ACE_Time_Value::zero,iter_delay);
}
int Client::handle_input(ACE_HANDLE)
{
char buf;
ssize_t recv_cnt=this->peer().recv(buf,sizeof(buf)-1);
if(recv_cnt>0)
{
ACE_DEBUG((LM_DEBUG,ACE_TEXT("%*C"),ACE_static_cast(int,recv_cnt),buf));
return 0;
}
if(recv_cnt==0||ACE_OS::last_error()!=EWOULDBLOCK)
{
this->reactor()->end_reactor_event_loop();
return -1;
}
return 0;
}
int Client::handle_output(ACE_HANDLE)
{
ACE_Message_Block *mb;
ACE_Time_Value nowait(ACE_OS::gettimeofday());
while(-1!=this->getq(mb,&nowait))
{
ssize_t send_cnt=this->peer().send(mb->rd_ptr(),mb->length());
if(send_cnt==-1) {}
else mb->rd_ptr(ACE_static_cast(size_t,send_cnt));
if(mb->length()>0)
{
this->ungetq(mb);
break;
}
mb->release();
}
if(this->msg_queue()->is_empty())
this->reactor()->cancel_wakeup(this,ACE_Event_Handler::WRITE_MASK);
else this->reactor()->schedule_wakeup(this,ACE_Event_Handler::WRITE_MASK);
return 0;
}
int Client::handle_timeout(const ACE_Time_Value&, const void*)
{
if(this->iterations_>=ITERATIONS)
{
this->peer().close_writer();
return 0;
}
ACE_Message_Block *mb;
char msg;
ACE_OS::sprintf (msg, "Iteration %d\n", this->iterations_);
ACE_NEW_RETURN (mb, ACE_Message_Block (msg), -1);
this->putq (mb);
return 0;
}
////////////////////////////////////////////////////////////////maintian.cpp////////////////////
#include"client.h"
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ACE_INET_Addr port_to_connect ("192.168.2.56:5000");
ACE_Connector<Client, ACE_SOCK_CONNECTOR> connector;
Client client;
Client *pc = &client;
if (connector.connect (pc, port_to_connect) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("connect")), 1);
ACE_Reactor::instance ()->run_reactor_event_loop ();
return (0);
}
最后通过
property pages
configuration properties /general /projectdefaults character set 改为not set
程序总算正常运作了 字符集差异,lib必须和主工程保持一致。
页:
[1]