当前位置: 技术问答>linux和unix
求教一个基本的socket问题~
来源: 互联网 发布时间:2016-02-16
本文导语: 我在一台机器上想利用socket实现不同进程间的通信,但是当我调用socket,bind,listen,accept函数编译时,出现以下错误: $ cc s.c undefined first referenced symbol ...
我在一台机器上想利用socket实现不同进程间的通信,但是当我调用socket,bind,listen,accept函数编译时,出现以下错误:
$ cc s.c
undefined first referenced
symbol in file
socket s.o
bind s.o
listen s.o
accept s.o
i386ld fatal: Symbol referencing errors. No output written to a.out
我用的版本是SCO UNIX 5。于是我去查看sys/socket.h,它的socket,bind,listen,accept函数分别定义为:
int socket __P((int, int, int));
int bind __P((int, const struct sockaddr *, int));
int listen __P((int, int));
int accept __P((int, struct sockaddr *, int *));
可我上网看的socket例子都没用这种函数定义的啊??
我把各个函数都改成以上形式,编译时还是出错:
$ cc s.c
"s.c", line 13: warning: argument mismatch
"s.c", line 13: error: Syntax error before or at: 1
"s.c", line 18: error: syntax error, probably missing ",", ";" or "="
"s.c", line 18: error: cannot recover from previous errors
源程序如下:
#include
#include
#include
#include
#include
#include
#define NAME "/tmp/socket"
main(void){
int orig_sock,new_sock,clnt_len,i;
static struct sockaddr_un clnt,serv;
static char buf[256];
if((orig_sock=(socket __P((AF_UNIX,SOCK_STREAM,0))))
$ cc s.c
undefined first referenced
symbol in file
socket s.o
bind s.o
listen s.o
accept s.o
i386ld fatal: Symbol referencing errors. No output written to a.out
我用的版本是SCO UNIX 5。于是我去查看sys/socket.h,它的socket,bind,listen,accept函数分别定义为:
int socket __P((int, int, int));
int bind __P((int, const struct sockaddr *, int));
int listen __P((int, int));
int accept __P((int, struct sockaddr *, int *));
可我上网看的socket例子都没用这种函数定义的啊??
我把各个函数都改成以上形式,编译时还是出错:
$ cc s.c
"s.c", line 13: warning: argument mismatch
"s.c", line 13: error: Syntax error before or at: 1
"s.c", line 18: error: syntax error, probably missing ",", ";" or "="
"s.c", line 18: error: cannot recover from previous errors
源程序如下:
#include
#include
#include
#include
#include
#include
#define NAME "/tmp/socket"
main(void){
int orig_sock,new_sock,clnt_len,i;
static struct sockaddr_un clnt,serv;
static char buf[256];
if((orig_sock=(socket __P((AF_UNIX,SOCK_STREAM,0))))