日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

我的makefile写法(一)

發布時間:2023/12/9 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 我的makefile写法(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?程序演示了一個通過tcp/ip通訊的server/client程序,都是簡單的C程序。源碼:

server.c

#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/types.h> #include <errno.h> #include<string.h>int readline(int fd, void *pbuf, int maxlen);int main(int argc,char **argv) {int fd,client_sockfd;int len;int ret;struct sockaddr_in remoteaddr;struct sockaddr_in localaddr;char buf[1024];//// 建立套接口// fd = socket(AF_INET, SOCK_STREAM, 0);if(fd == -1){printf("socket() error %d\n",errno);return -1;}//// 綁定地址和端口//localaddr.sin_family = AF_INET;localaddr.sin_addr.s_addr = htonl(INADDR_ANY); localaddr.sin_port = htons(5000); len = sizeof(localaddr); if(bind(fd, (struct sockaddr *)&localaddr, len) == -1){printf("bind() error\n");return -1;}//// 建立套接口隊列//if(listen(fd, 5) == -1){printf("listen() error\n");return -1;}//// 等待 // len = sizeof(remoteaddr); printf("server recieve connect!--\n");int i = 0;while(1){printf("\nWaiting for ...\n"); // fflush(stdout);client_sockfd = accept(fd,(struct sockaddr *)&remoteaddr, &len);// // 接收數據//ret = recv(client_sockfd, (void *)buf, 1024, 0);if(ret <= 0){printf("server recieve data failed!--\n");} else{printf("server read line:%s\n", buf); }memset(buf,0x00,sizeof(buf));// strcpy(buf,"How are you?");sprintf(buf, "%d: How are you?", ++i);sleep(3);ret = send(client_sockfd, (void *)buf, strlen(buf),0);if(ret <= 0){printf("server send() error\n");}memset(buf,0x00,sizeof(buf));//關閉聯接 close(client_sockfd);printf("close client\n"); }return 0; }

?

client.c

#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/types.h> #include <errno.h> #include <string.h> #include <stdlib.h>int main(int argc,char **argv) {int fd;int len,ret;struct sockaddr_in remoteaddr;char data[1024];int times = 1;//// 建立套接口// fd = socket(AF_INET, SOCK_STREAM, 0);//// 連接//remoteaddr.sin_family = AF_INET;remoteaddr.sin_addr.s_addr = inet_addr("127.0.0.1");remoteaddr.sin_port = htons(5000);len = sizeof(remoteaddr);ret = connect(fd, (struct sockaddr *)&remoteaddr, len);if(ret == -1) {printf("connect() error\n");return -1;}//while(1){//發送數據printf("The %d times run\n", times++);sprintf(data,"%s","hello world");ret = send(fd, (void *)data, strlen(data),0);if(ret <= 0){printf("send() error\n");}printf("sent line:%s\n", data);bzero(data,1024);sleep(1);ret = recv(fd, (void *)data, 1024, 0);if(ret <= 0){printf("server recieve data failed!--\n");} else{int id = atoi(data);printf("client[id=%d] read str:[%s]\n", id, data);}}printf("client exited.\n");//// 關閉// finish: close(fd);fd = -1;return 0; }

?

再掛上我的Makefile:

install: myserver myclientmyserver: server.ogcc -o myserver server.o#server.o: server.cmyclient: client.ogcc -o myclient client.o#client.o: client.cclean:rm -f *.o my*

?

掛上我的這個makefile,主要是為了說明:

1. 我這個文件相互之間沒有依賴性。

2. server.o依賴于server.c,所以這個依賴規則在makefile文件中可以不寫,它默認已經存在的。

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的我的makefile写法(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。