繁体   English   中英

Cygwin GCC编译错误

[英]Cygwin gcc compiling error

我试图在CYGWIN gcc中编译C套接字程序,但是当我编译客户端程序时,出现以下错误

client.h: In function ‘error’:
client.h:11:5: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
     exit(1);
     ^
client.h: In function ‘main’:
client.h:30:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
         exit(0);
         ^
client.h:36:5: warning: passing argument 2 of ‘connect’ from incompatible pointer type [enabled by default]
     if(connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
     ^
In file included from client.h:3:0:
/usr/include/sys/socket.h:28:7: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
   int connect (int, const struct sockaddr *, socklen_t);
       ^

当我尝试编译服务器程序时,出现以下错误

server.h: In function ‘error’:
server.h:8:5: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
     exit(1);
     ^
server.h: In function ‘main’:
server.h:18:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
         exit(1);
         ^
server.h:23:5: warning: incompatible implicit declaration of built-in function ‘bzero’ [enabled by default]
     bzero((char *) &serv_addr, sizeof(serv_addr));
     ^
server.h:32:64: error: ‘client’ undeclared (first use in this function)
     newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &client);
                                                                ^
server.h:32:64: note: each undeclared identifier is reported only once for each function it appears in

那么解决方案是什么

客户端代码中的错误是因为您将指向struct sockaddr_in的指针传递给了一个参数,该参数期望它是指向struct sockaddr的指针。 错误消息基本上说明了一切。 服务器代码中的错误是因为未在任何地方声明变量client

这些警告是由于不包含包含exit声明(include stdlib.h )和bzero (include strings.h )的适当包含文件引起的。 因此,您将获得一个隐式声明,并且由于编译器将这些函数视为标准的内置函数,因此它在警告中也提到了这一点。

好了,问题是我试图在Windows中编译Linux程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM