0

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

それで、これに対する解決策は何ですか

4

2 に答える 2

3

クライアント コードのエラーは、へのポインタを へのポインタstruct sockaddr_inであると想定するパラメータに へのポインタを渡すためですstruct sockaddr。エラーメッセージは基本的にすべてを示しています。サーバー コードのエラーは、変数clientがどこにも宣言されていないことが原因です。

exit警告は、 (include stdlib.h) およびbzero(include )の宣言を含む適切なインクルード ファイルが含まれていないために発生しますstrings.h。したがって、暗黙的な宣言が得られ、コンパイラはこれらの関数を標準の組み込み関数として認識しているため、警告にもそのことが記載されています。

于 2013-08-17T16:44:16.410 に答える