当前位置: 技术问答>linux和unix
Socket程序--编译后提示未定义标识?
来源: 互联网 发布时间:2015-08-22
本文导语: 代码: /一个SOCKET程序的客户端 #include #include #include #include #include #include #include #define PORT 9311 #define SRV_ADDR "172.20.11.10" main() { int sock_fd,len; char * msg; struct sockaddr_in srva...
代码:
/一个SOCKET程序的客户端
#include
#include
#include
#include
#include
#include
#include
#define PORT 9311
#define SRV_ADDR "172.20.11.10"
main()
{
int sock_fd,len;
char * msg;
struct sockaddr_in srvaddr;
srvaddr.sin_family=AF_INET;
srvaddr.sin_port=htons(PORT);
srvaddr.sin_addr.s_addr=inet_addr(SRV_ADDR);
bzero(&(srvaddr.sin_zero));
socket(AF_INET,SOCK_STREAM,0);
if(sock_fd==-1)
{
printf("Create socket error !");
exit(1);
}
connect(sock_fd,(struct sockaddr *)&srvaddr,sizeof(struct sockaddr));
msg="你好,我在客户端向服务器问好!";
len=strlen(msg);
send(sock_fd,msg,len,0);
close(sock_fd);
}
我用cc client.c命令编译后出现如下错误,
错误:
undefined first referenced
symbol in file
htons client.o
inet_addr client.o
socket client.o
connect client.o
send client.o
i386ld fatal: Symbol referencing errors. No output written to a.out
恳请高人指点!小弟感激不尽!
/一个SOCKET程序的客户端
#include
#include
#include
#include
#include
#include
#include
#define PORT 9311
#define SRV_ADDR "172.20.11.10"
main()
{
int sock_fd,len;
char * msg;
struct sockaddr_in srvaddr;
srvaddr.sin_family=AF_INET;
srvaddr.sin_port=htons(PORT);
srvaddr.sin_addr.s_addr=inet_addr(SRV_ADDR);
bzero(&(srvaddr.sin_zero));
socket(AF_INET,SOCK_STREAM,0);
if(sock_fd==-1)
{
printf("Create socket error !");
exit(1);
}
connect(sock_fd,(struct sockaddr *)&srvaddr,sizeof(struct sockaddr));
msg="你好,我在客户端向服务器问好!";
len=strlen(msg);
send(sock_fd,msg,len,0);
close(sock_fd);
}
我用cc client.c命令编译后出现如下错误,
错误:
undefined first referenced
symbol in file
htons client.o
inet_addr client.o
socket client.o
connect client.o
send client.o
i386ld fatal: Symbol referencing errors. No output written to a.out
恳请高人指点!小弟感激不尽!
|
cc client.c -lsocket