[英]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.