我嘗試編譯Cygwin中GCC一個C套接字程序,但是當我編譯客戶端程序,它給了我下面的錯誤Cygwin的GCC編譯錯誤
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
那麼什麼是解決這個
對於初學者,不要將代碼放在頭文件中。只是函數聲明。 .c文件是實際應用的地方。這可能是問題的一部分。它看到頭文件中使用了「exit()」。此外,還要展示一個最低限度的例子(即向我們展示您的代碼),瞭解哪些功能無法使用 – selbie
你可以在這裏找到我的代碼http://stackoverflow.com/questions/17971513/socket-program-in-c-cannot-compile – mega6382
你是否包含'stdlib.h'?然後你可以看到退出已經被聲明,你不應該再次聲明它。它是一個不應該重新定義的函數構建。 – hetepeperfan