我下的是ACE5.5版本,编译用的是“ACE_Static.sln”文件,选择的“Release”,按照《中篇:ACE程序员教程》里的第一个例子写好程序,头文件和库文件路径都设好了,附加库文件也添加了“ACEs.lib”,链接报错。为了排除设置问题,我在VS的命令提示符下用link命令手动链接,还是同样的错误。ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Acceptor::~ACE_SOCK_Acceptor(void)" (__imp_??1ACE_SOCK_Acceptor@@QAE@XZ) referenced in function $L28134
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Stream::~ACE_SOCK_Stream(void)" (__imp_??1ACE_SOCK_Stream@@QAE@XZ) referenced in function $L28134
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall ACE_INET_Addr::~ACE_INET_Addr(void)" (__imp_??1ACE_INET_Addr@@UAE@XZ) referenced in function $L28134
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Stream::ACE_SOCK_Stream(void)" (__imp_??0ACE_SOCK_Stream@@QAE@XZ) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Acceptor::ACE_SOCK_Acceptor(class ACE_Addr const &,int,int,int,int)" (__imp_??0ACE_SOCK_Acceptor@@QAE@ABVACE_Addr@@HHHH@Z) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_INET_Addr::ACE_INET_Addr(void)" (__imp_??0ACE_INET_Addr@@QAE@XZ) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_INET_Addr::ACE_INET_Addr(unsigned short,unsigned int)" (__imp_??0ACE_INET_Addr@@QAE@GI@Z) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK_Stream::close(void)" (__imp_?close@ACE_SOCK_Stream@@QAEHXZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl ACE_Log_Msg::log(enum ACE_Log_Priority,char const *,...)" (__imp_?log@ACE_Log_Msg@@QAAHW4ACE_Log_Priority@@PBDZZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall ACE_Log_Msg::conditional_set(char const *,int,int,int)" (__imp_?conditional_set@ACE_Log_Msg@@QAEXPBDHHH@Z) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK_Stream::recv_n(void *,unsigned int,int,class ACE_Time_Value const *,unsigned int *)const " (__imp_?recv_n@ACE_SOCK_Stream@@QBEHPAXIHPBVACE_Time_Value@@PAI@Z) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class ACE_Log_Msg * __cdecl ACE_Log_Msg::instance(void)" (__imp_?instance@ACE_Log_Msg@@SAPAV1@XZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl ACE_Log_Msg::last_error_adapter(void)" (__imp_?last_error_adapter@ACE_Log_Msg@@SAHXZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall ACE_INET_Addr::get_host_name(void)const " (__imp_?get_host_name@ACE_INET_Addr@@QBEPBDXZ) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK_Acceptor::accept(class ACE_SOCK_Stream &,class ACE_Addr *,class ACE_Time_Value *,int,int)const " (__imp_?accept@ACE_SOCK_Acceptor@@QBEHAAVACE_SOCK_Stream@@PAVACE_Addr@@PAVACE_Time_Value@@HH@Z) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_Time_Value::ACE_Time_Value(long,long)" (__imp_??0ACE_Time_Value@@QAE@JJ@Z) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned short __thiscall ACE_INET_Addr::get_port_number(void)const " (__imp_?get_port_number@ACE_INET_Addr@@QBEGXZ) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK::get_local_addr(class ACE_Addr &)const " (__imp_?get_local_addr@ACE_SOCK@@QBEHAAVACE_Addr@@@Z) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ace_os_main_i(class ACE_Main_Base &,int,char * * const)" (__imp_?ace_os_main_i@@YAHAAVACE_Main_Base@@HQAPAD@Z) referenced in function _main
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ACE_OS::atoi(char const *)" (__imp_?atoi@ACE_OS@@YAHPBD@Z) referenced in function "int __cdecl ace_main_i(int,char * * const)" (?ace_main_i@@YAHHQAPAD@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl ACE_OS::exit(int)" (__imp_?exit@ACE_OS@@YAXH@Z) referenced in function "int __cdecl ace_main_i(int,char * * const)" (?ace_main_i@@YAHHQAPAD@Z)
ace_1 fatal error LNK1120: 21 unresolved externals
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Stream::~ACE_SOCK_Stream(void)" (__imp_??1ACE_SOCK_Stream@@QAE@XZ) referenced in function $L28134
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall ACE_INET_Addr::~ACE_INET_Addr(void)" (__imp_??1ACE_INET_Addr@@UAE@XZ) referenced in function $L28134
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Stream::ACE_SOCK_Stream(void)" (__imp_??0ACE_SOCK_Stream@@QAE@XZ) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_SOCK_Acceptor::ACE_SOCK_Acceptor(class ACE_Addr const &,int,int,int,int)" (__imp_??0ACE_SOCK_Acceptor@@QAE@ABVACE_Addr@@HHHH@Z) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_INET_Addr::ACE_INET_Addr(void)" (__imp_??0ACE_INET_Addr@@QAE@XZ) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_INET_Addr::ACE_INET_Addr(unsigned short,unsigned int)" (__imp_??0ACE_INET_Addr@@QAE@GI@Z) referenced in function "public: __thiscall Server::Server(int)" (??0Server@@QAE@H@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK_Stream::close(void)" (__imp_?close@ACE_SOCK_Stream@@QAEHXZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl ACE_Log_Msg::log(enum ACE_Log_Priority,char const *,...)" (__imp_?log@ACE_Log_Msg@@QAAHW4ACE_Log_Priority@@PBDZZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall ACE_Log_Msg::conditional_set(char const *,int,int,int)" (__imp_?conditional_set@ACE_Log_Msg@@QAEXPBDHHH@Z) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK_Stream::recv_n(void *,unsigned int,int,class ACE_Time_Value const *,unsigned int *)const " (__imp_?recv_n@ACE_SOCK_Stream@@QBEHPAXIHPBVACE_Time_Value@@PAI@Z) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class ACE_Log_Msg * __cdecl ACE_Log_Msg::instance(void)" (__imp_?instance@ACE_Log_Msg@@SAPAV1@XZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl ACE_Log_Msg::last_error_adapter(void)" (__imp_?last_error_adapter@ACE_Log_Msg@@SAHXZ) referenced in function "public: int __thiscall Server::handle_connection(void)" (?handle_connection@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall ACE_INET_Addr::get_host_name(void)const " (__imp_?get_host_name@ACE_INET_Addr@@QBEPBDXZ) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK_Acceptor::accept(class ACE_SOCK_Stream &,class ACE_Addr *,class ACE_Time_Value *,int,int)const " (__imp_?accept@ACE_SOCK_Acceptor@@QBEHAAVACE_SOCK_Stream@@PAVACE_Addr@@PAVACE_Time_Value@@HH@Z) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_Time_Value::ACE_Time_Value(long,long)" (__imp_??0ACE_Time_Value@@QAE@JJ@Z) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned short __thiscall ACE_INET_Addr::get_port_number(void)const " (__imp_?get_port_number@ACE_INET_Addr@@QBEGXZ) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_SOCK::get_local_addr(class ACE_Addr &)const " (__imp_?get_local_addr@ACE_SOCK@@QBEHAAVACE_Addr@@@Z) referenced in function "public: int __thiscall Server::accept_connections(void)" (?accept_connections@Server@@QAEHXZ)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ace_os_main_i(class ACE_Main_Base &,int,char * * const)" (__imp_?ace_os_main_i@@YAHAAVACE_Main_Base@@HQAPAD@Z) referenced in function _main
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ACE_OS::atoi(char const *)" (__imp_?atoi@ACE_OS@@YAHPBD@Z) referenced in function "int __cdecl ace_main_i(int,char * * const)" (?ace_main_i@@YAHHQAPAD@Z)
ace_1 error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl ACE_OS::exit(int)" (__imp_?exit@ACE_OS@@YAXH@Z) referenced in function "int __cdecl ace_main_i(int,char * * const)" (?ace_main_i@@YAHHQAPAD@Z)
ace_1 fatal error LNK1120: 21 unresolved externals
解决方案 »
- TransmitFile会消耗大量的时间
- CTreeCtrlEX树形菜单换行
- opengl请教
- 如何改变edit空间中光标的颜色,或者让光标不显示!!!!!!!!!!!!
- 如何将一个已有的bmp图片---GDI+中的Bitmap*变量,保存到自己定义的file文件中?
- HELP ME ~~为什么我的 Visual Assist X 安装以后,在 VC 的环境里的程序文件,一些关键字的颜色显示还是没有区别???
- 关于模板的问题,编译不能通过为什么?
- 关于动态创建的控件的消息处理,大家来帮帮忙!
- 北京的VC 热心网友注意了
- 为什么ClassWizard无法打开
- 如果得到2000/XP的桌面句柄??使用GetDesktopWindow函数只能得到WIN98的桌面句柄,在线等
- 大虾们,请进,关于改变窗口大小的问题。谢谢
#include <ace/SOCK_Stream.h>
#include <ace/OS.h>
#include <ace/Log_Msg.h>#define SIZE_DATA 18
#define SIZE_BUF 1024
#define NO_ITERATIONS 5
class Server
{
public:
Server (int port): server_addr_(port),peer_acceptor_(server_addr_)
{
data_buf_= new char[SIZE_BUF];
}
//Handle the connection once it has been established. Here the
//connection is handled by reading SIZE_DATA amount of data from the
//remote and then closing the connection stream down.
int handle_connection()
{
// Read data from client
for(int i=0;i<NO_ITERATIONS;i++)
{
int byte_count=0;
if( (byte_count=new_stream_.recv_n (data_buf_, SIZE_DATA, 0))==-1)
ACE_ERROR ((LM_ERROR, "%p\n", "Error in recv"));
else
{
data_buf_[byte_count]=0;
ACE_DEBUG((LM_DEBUG,"Server received %s \n",data_buf_));
}
}
// Close new endpoint
if (new_stream_.close () == -1)
ACE_ERROR ((LM_ERROR, "%p\n", "close"));
return 0;
}
//Use the acceptor component peer_acceptor_ to accept the connection
//into the underlying stream new_stream_. After the connection has been
//established call the handle_connection() method.
int accept_connections ()
{
if (peer_acceptor_.get_local_addr (server_addr_) == -1)
ACE_ERROR_RETURN ((LM_ERROR,"%p\n","Error in get_local_addr"),1);
ACE_DEBUG ((LM_DEBUG,"Starting server at port %d\n",
server_addr_.get_port_number ()));
// Performs the iterative server activities.
while(1)
{
ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);
if (peer_acceptor_.accept (new_stream_, &client_addr_, &timeout)== -1)
{
ACE_ERROR ((LM_ERROR, "%p\n", "accept"));
continue;
}
else
{
ACE_DEBUG((LM_DEBUG,
"Connection established with remote %s:%d\n",
client_addr_.get_host_name(),client_addr_.get_port_number()));
//Handle the connection
handle_connection();
}
}
}
private:
char *data_buf_;
ACE_INET_Addr server_addr_;
ACE_INET_Addr client_addr_;
ACE_SOCK_Acceptor peer_acceptor_;
ACE_SOCK_Stream new_stream_;
};
int main (int argc, char *argv[])
{
if(argc<2)
{
ACE_ERROR((LM_ERROR,"Usage %s <port_num>", argv[0]));
ACE_OS::exit(1);
}
Server server(ACE_OS::atoi(argv[1]));
server.accept_connections();
return 0;
}困惑啊..
或者在工程设置里,在Input Library中添加
你静态链接ACE的库,编译ok了,但是你的工程配置有问题,尽管添加了ACEs.lib。
真正的解决方法是:
在使用ACE的工程中,需要加入ACE_AS_STATIC_LIBS宏定义。在C++配置项目里面,加上就好了。──────────────────────
国内专业的ACE网络编程、开发论坛开通:
www.acejoy.com
www.acedevelop.com
涉及ACE使用和开发,中间件、服务器端软件的设计,P2P技术,
socket网络编程、应用开发等内容。
欢迎加入,大家一起交流、学习成长!