刚入此道,打击信心。

tan625747 2009-06-19 05:40:28
学网络编程,正学习套接字编程。
用visual c++.net 2003的版本,运行服务端程序出错。

server.obj : error LNK2019: 无法解析的外部符号 "unsigned int __cdecl TCPserver(char const *,int)" (?TCPserver@@YAIPBDH@Z) ,该符号在函数 _main 中被引用
Debug/server.exe : fatal error LNK1120: 1 个无法解析的外部命令。

不知道是什么原因,上网查了半天,看了前辈的解决方法,http://topic.csdn.net/t/20040627/16/3126300.html

遇到情况估计跟那位前辈的一样。
可还是没有解决。
...全文
52 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
greatws 2009-06-20
  • 打赏
  • 举报
回复
SOCKET TCPserver(const char *service,int qlen);
这个函数的函数体在哪啊?
spring203 2009-06-20
  • 打赏
  • 举报
回复
楼主, #include "passive_sever.c"
有没有把这个文件包含进工程呀。
tan625747 2009-06-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 xhk456 的回复:]
初级错误,知道了,以后就不会再犯了
[/Quote]

相信是初级错误,可不知道怎么改。
tan625747 2009-06-20
  • 打赏
  • 举报
回复
可能是viaul c++.net 2003这个软件有问题,弄好几个程序,没有 个能执行成功。


请问一下大家我只想学网络编程,将来能做一个C/S 和B/S 模型 相结合的项目,我应该学什么语言呀?

谢谢大家啦。
似水流年__ 2009-06-19
  • 打赏
  • 举报
回复
初级错误,知道了,以后就不会再犯了
msdn2009_2010 2009-06-19
  • 打赏
  • 举报
回复
UP
tan625747 2009-06-19
  • 打赏
  • 举报
回复
passive_sever.c代码,有可能出错在这个文件上
#pragma comment(lib, "WSock32.Lib")。
  #pragma   comment(linker,   "/subsystem:console ") 
#include <WinSock.h>
#pragma comment(lib, "WSock32.Lib")
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "passive_sever.c"



#define QLEN 5
#define BUFSIZE 2048
#define WAVERS MAKEWORD(2,0)

SOCKET TCPserver(const char *service,int qlen);



void main(int argc,char *argv[])
{
char *service = "5555";
struct sockaddr_in fsin;
SOCKET msock,ssock;
WSADATA wsadata;
int alen,cc;
char buf[BUFSIZE];

switch(argc)
{
case 1:
break;
case 2:
service=argv[1];
break;
default:
printf("argment error\n");
exit(1);
}

if(WSAStartup(WAVERS,&wsadata)!=0)
{
printf("initalize failed\n");
WSACleanup();
exit(1);
}

msock=TCPserver(service,QLEN);

while(1){
alen=sizeof(struct sockaddr);
ssock=accept(msock,(struct sockaddr *)&fsin,&alen);

if(ssock==INVALID_SOCKET)
{
printf("initalize failed\n");
WSACleanup();
exit(1);
}
buf[0]='\n';
while( cc=recv(ssock,buf,sizeof(buf)-1,0) ){
buf[cc]='\0';
printf("%s",buf);

}
printf("connect close... ");
closesocket(ssock);
break;

}


}

greatws 2009-06-19
  • 打赏
  • 举报
回复
TCPserver 这个函数的实现在哪?
tan625747 2009-06-19
  • 打赏
  • 举报
回复
Nihao: to wenxy1

[Quote=引用 5 楼 wenxy1 的回复:]
TCPserver这个函数在哪个库定义的,链接它:
#pragma comment(lib, "lib_name_??")
[/Quote]

关于链接它还不太会呢,还是谢了。

我刚看到这篇
http://topic.csdn.net/u/20090130/13/32f375af-d2d4-41b9-a1b5-6acd1c227ee3.html
不过我坏境是visual c++.net 2003
Wenxy1 2009-06-19
  • 打赏
  • 举报
回复
TCPserver这个函数在哪个库定义的,链接它:
#pragma comment(lib, "lib_name_??")
tan625747 2009-06-19
  • 打赏
  • 举报
回复
Nihao: to na_he
怎么把 TCPserver定义的所在类的lib添加在工程里面?
na_he 2009-06-19
  • 打赏
  • 举报
回复
TCPserver定义的所在类的lib没有添加在工程里面。
tan625747 2009-06-19
  • 打赏
  • 举报
回复
服务端server.cpp
  #pragma   comment(linker,   "/subsystem:console ") 
#include <WinSock.h>
#pragma comment(lib, "WSock32.Lib")
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "passive_sever.c"



#define QLEN 5
#define BUFSIZE 2048
#define WAVERS MAKEWORD(2,0)

SOCKET TCPserver(const char *service,int qlen);



void main(int argc,char *argv[])
{
char *service = "5555";
struct sockaddr_in fsin;
SOCKET msock,ssock;
WSADATA wsadata;
int alen,cc;
char buf[BUFSIZE];

switch(argc)
{
case 1:
break;
case 2:
service=argv[1];
break;
default:
printf("argment error\n");
exit(1);
}

if(WSAStartup(WAVERS,&wsadata)!=0)
{
printf("initalize failed\n");
WSACleanup();
exit(1);
}

msock=TCPserver(service,QLEN);

while(1){
alen=sizeof(struct sockaddr);
ssock=accept(msock,(struct sockaddr *)&fsin,&alen);

if(ssock==INVALID_SOCKET)
{
printf("initalize failed\n");
WSACleanup();
exit(1);
}
buf[0]='\n';
while( cc=recv(ssock,buf,sizeof(buf)-1,0) ){
buf[cc]='\0';
printf("%s",buf);

}
printf("connect close... ");
closesocket(ssock);
break;

}


}

blackcat242 2009-06-19
  • 打赏
  • 举报
回复
这根网络没关系
看看这个函数实现了么

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧