{"id":184,"date":"2025-07-18T18:38:40","date_gmt":"2025-07-18T10:38:40","guid":{"rendered":"http:\/\/www.tgwttt.xyz\/?p=184"},"modified":"2025-11-24T16:40:58","modified_gmt":"2025-11-24T08:40:58","slug":"makefile","status":"publish","type":"post","link":"https:\/\/www.tgwttt.xyz\/?p=184","title":{"rendered":"Makefile"},"content":{"rendered":"\n<p>\u4f1a\u4e0d\u4f1a\u5199makefile\uff0c\u4ece\u2f00\u4e2a\u4fa7\u2faf\u8bf4\u660e\u4e86\u2f00\u4e2a\u2f08\u662f\u5426\u5177\u5907\u5b8c\u6210\u2f24\u578b\u2f2f\u7a0b\u7684\u80fd\u2f12 <\/p>\n\n\n\n<p>\u2f00\u4e2a\u2f2f\u7a0b\u4e2d\u7684\u6e90\u2f42\u4ef6\u4e0d\u8ba1\u6570\uff0c\u5176\u6309\u7c7b\u578b\u3001\u529f\u80fd\u3001\u6a21\u5757\u5206\u522b\u653e\u5728\u82e5\u2f32\u4e2a\u2f6c\u5f55\u4e2d\uff0cmakefile\u5b9a\u4e49\u4e86\u2f00\u7cfb\u5217\u7684\u89c4\u5219\u6765\u6307\u5b9a\uff0c\u54ea\u4e9b\u2f42\u4ef6\u9700\u8981\u5148\u7f16\u8bd1\uff0c\u54ea\u4e9b\u2f42\u4ef6\u9700\u8981\u540e\u7f16\u8bd1\uff0c\u54ea\u4e9b\u2f42\u4ef6\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\uff0c\u751a\u2f84\u4e8e\u8fdb\u2f8f\u66f4\u590d\u6742\u7684\u529f\u80fd\u64cd\u4f5c makefile\u5e26\u6765\u7684\u597d\u5904\u5c31\u662f\u2e3a\u201c\u2f83\u52a8\u5316\u7f16\u8bd1\u201d\uff0c\u2f00\u65e6\u5199\u597d\uff0c\u53ea\u9700\u8981\u2f00\u4e2amake\u547d\u4ee4\uff0c\u6574\u4e2a\u2f2f\u7a0b\u5b8c\u5168\u2f83\u52a8\u7f16\u8bd1\uff0c\u6781\u2f24\u7684\u63d0\u2fbc\u4e86\u8f6f\u4ef6\u5f00\u53d1\u7684\u6548\u7387\u3002 <\/p>\n\n\n\n<p>make\u662f\u2f00\u4e2a\u547d\u4ee4\u2f2f\u5177\uff0c\u662f\u2f00\u4e2a\u89e3\u91camakefile\u4e2d\u6307\u4ee4\u7684\u547d\u4ee4\u2f2f\u5177\uff0c\u2f00\u822c\u6765\u8bf4\uff0c\u2f24\u591a\u6570\u7684IDE\u90fd\u6709\u8fd9\u4e2a\u547d\u4ee4\uff0c\u2f50\u5982\uff1aDelphi\u7684make\uff0cVisual C++\u7684nmake\uff0cLinux\u4e0bGNU\u7684make\u3002\u53ef\u2ec5\uff0cmakefile\u90fd\u6210\u4e3a\u4e86\u2f00\u79cd\u5728\u2f2f\u7a0b\u2f45\u2faf\u7684\u7f16\u8bd1\u2f45\u6cd5\u3002<\/p>\n\n\n\n<p>\u57fa\u672c\u4f7f\u7528\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>myproc.c\u6587\u4ef6\n#include <stdio.h>\nint main(){\nprintf(\"hello Makefile!\\n\");return 0;\n}\nMakefile\u2f42\u4ef6\nmyproc:myproc.c\ngcc -o myproc myproc.c\n.PHONY:clean\nclean:\nrm -f myproc\n\u4f9d\u8d56\u5173\u7cfb\n\u4e0a\u2faf\u7684\u2f42\u4ef6myproc,\u5b83\u4f9d\u8d56myproc.c \n\u4f9d\u8d56\u2f45\u6cd5\ngcc -o myproc myproc.c  ,\u5c31\u662f\u4e0e\u4e4b\u5bf9\u5e94\u7684\u4f9d\u8d56\u5173\u7cfb \n\u9879\u2f6c\u6e05\u7406\nclean:\u2f2f\u7a0b\u662f\u9700\u8981\u88ab\u6e05\u7406\u7684\n.PHONY:\u8ba9make\u5ffd\u7565\u6e90\u2f42\u4ef6\u548c\u53ef\u6267\u2f8f\u2f6c\u6807\u2f42\u4ef6\u7684M\u65f6\u95f4\u5bf9\u2f50 <\/code><\/pre>\n\n\n\n<p>\u7f16\u8bd1\u547d\u4ee4\uff1amake\uff0c\u6e05\u9664\u547d\u4ee4make clean                                                                                                                        \u4e3a\u4ec0\u4e48make\u5c31\u80fd\u76f4\u63a5\u6267\u884c\u7f16\u8bd1\u6587\u4ef6\uff0c\u6e05\u9664\u4e3a\u4ec0\u4e48\u9700\u8981make clean\u547d\u4ee4\u5462\uff1f                                                           make\u5728\u6267\u884c\u65f6\u9ed8\u8ba4\u6267\u884c\u7b2c\u4e00\u4e2a\uff0c\u9664\u975e\u660e\u786e\u6307\u51famake clean,\u624d\u4f1a\u53bb\u6267\u884c<\/p>\n\n\n\n<p>makefile\u7684\u5de5\u4f5c\u539f\u7406\uff1a 1. make\u4f1a\u5728\u5f53\u524d\u2f6c\u5f55\u4e0b\u627e\u540d\u5b57\u53eb\u201cMakefile\u201d\u6216\u201cmakefile\u201d\u7684\u2f42\u4ef6\u3002<\/p>\n\n\n\n<p> 2. \u5982\u679c\u627e\u5230\uff0c\u5b83\u4f1a\u627e\u2f42\u4ef6\u4e2d\u7684\u7b2c\u2f00\u4e2a\u2f6c\u6807\u2f42\u4ef6\uff08target\uff09\uff0c\u5728\u4e0a\u2faf\u7684\u4f8b\u2f26\u4e2d\uff0c\u4ed6\u4f1a\u627e\u5230 myproc \u8fd9\u4e2a\u2f42\u4ef6\uff0c\u5e76\u628a\u8fd9\u4e2a\u2f42\u4ef6\u4f5c\u4e3a\u6700\u7ec8\u7684\u2f6c\u6807\u2f42\u4ef6\u3002 <\/p>\n\n\n\n<p>3. \u5982\u679c myproc \u2f42\u4ef6\u4e0d\u5b58\u5728\uff0c\u6216\u662f myproc \u6240\u4f9d\u8d56\u7684\u540e\u2faf\u7684 myproc.o \u2f42\u4ef6\u7684\u2f42\u4ef6\u4fee\u6539\u65f6\u95f4\u8981\u8fd9\u4e2amyproc<br>\u2f42\u4ef6\u65b0\uff08\u53ef\u4ee5\u2f64 touch \u6d4b\u8bd5\uff09\uff0c\u90a3\u4e48\uff0c\u4ed6\u5c31\u4f1a\u6267\u2f8f\u540e\u2faf\u6240\u5b9a\u4e49\u7684\u547d\u4ee4\u6765\u2f63\u6210\u8fd9\u4e2amyproc\u2f42\u4ef6\u3002 <\/p>\n\n\n\n<p>4.\u5982\u679c myproc \u6240\u4f9d\u8d56\u7684 myproc.o \u2f42\u4ef6\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48 make \u4f1a\u5728\u5f53\u524d\u2f42\u4ef6\u4e2d\u627e\u2f6c\u6807\u4e3amyproc myproc.o \u2f42\u4ef6\u7684\u4f9d\u8d56\u6027\uff0c\u5982\u679c\u627e\u5230\u5219\u518d\u6839\u636e\u90a3\u2f00\u4e2a\u89c4\u5219\u2f63\u6210 myproc.o \u2f42\u4ef6\u3002\uff08\u8fd9\u6709\u70b9\u50cf\u2f00\u4e2a\u5806\u6808\u7684\u8fc7\u7a0b\uff09 <\/p>\n\n\n\n<p>5. \u5f53\u7136\uff0c\u4f60\u7684C\u2f42\u4ef6\u548cH\u2f42\u4ef6\u662f\u5b58\u5728\u7684\u5566\uff0c\u4e8e\u662f make \u4f1a\u2f63\u6210 myproc.o \u2f42\u4ef6\uff0c\u7136\u540e\u518d\u2f64 myproc.o \u2f42\u4ef6\u58f0\u660e make \u7684\u7ec8\u6781\u4efb\u52a1\uff0c\u4e5f\u5c31\u662f\u6267\u2f8f\u2f42\u4ef6 hello \u4e86\u3002<\/p>\n\n\n\n<p> 6. \u8fd9\u5c31\u662f\u6574\u4e2amake\u7684\u4f9d\u8d56\u6027\uff0cmake\u4f1a\u2f00\u5c42\u2f1c\u2f00\u5c42\u5730\u53bb\u627e\u2f42\u4ef6\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u76f4\u5230\u6700\u7ec8\u7f16\u8bd1\u51fa\u7b2c\u2f00\u4e2a\u2f6c\u6807\u2f42\u4ef6\u3002 <\/p>\n\n\n\n<p>7. \u5728\u627e\u5bfb\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff0c\u2f50\u5982\u6700\u540e\u88ab\u4f9d\u8d56\u7684\u2f42\u4ef6\u627e\u4e0d\u5230\uff0c\u90a3\u4e48make\u5c31\u4f1a\u76f4\u63a5\u9000\u51fa\uff0c\u5e76\u62a5\u9519\uff0c\u2f7d\u5bf9\u4e8e\u6240\u5b9a\u4e49\u7684\u547d\u4ee4\u7684\u9519\u8bef\uff0c\u6216\u662f\u7f16\u8bd1\u4e0d\u6210\u529f\uff0cmake\u6839\u672c\u4e0d\u7406\u3002make\u4f1a\u2f00\u5c42\u2f1c\u2f00\u5c42\u5730\u53bb\u627e\u2f42\u4ef6\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u76f4\u5230\u6700\u7ec8\u7f16\u8bd1\u51fa\u7b2c\u2f00\u4e2a\u2f6c\u6807\u2f42\u4ef6\u3002<\/p>\n\n\n\n<p>\u6269\u5c55\u8bed\u6cd5\uff1a                                                                                                                                                                   <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2025\/png\/50466557\/1752807392026-8a320cf3-fa49-46f1-97a4-5621a7cd640a.png\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\"><\/div>\n<\/div>\n\n\n\n<p>\u4ee5\u53d8\u91cf\u7684\u5f62\u5f0f\u53bb\u7f16\u8f91makefile<\/p>\n\n\n\n<p id=\"u48226e11\">$@\uff1a\u76ee\u6807\u6587\u4ef6<\/p>\n\n\n\n<p id=\"u41f8b83c\">$^:\u4f17\u591a\u6587\u4ef6\u5217\u8868<\/p>\n\n\n\n<p>\u5e26\u4e0a@:\u5c31\u4e0d\u4f1a\u56de\u663e\u547d\u4ee4<\/p>\n\n\n\n<p id=\"u2772f47d\">%.o:%.cpp<\/p>\n\n\n\n<p id=\"u8108e5df\">$<\uff1a\u5c06%.c\u548c%.cpp\u4f9d\u6b21\u5c55\u5f00<\/p>\n\n\n\n<p id=\"u443a85ea\">$(shell ls *.cpp)\u83b7\u53d6ls\u547d\u4ee4\u4e2d\u5339\u914d*.cpp\u7684\u6587\u4ef6<\/p>\n\n\n\n<p id=\"u394e171a\">$(SRC:.cpp=.o):\u5c06SRC\u4e2d.cpp\u6362\u6210.o<\/p>\n\n\n\n<p>makefile\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\uff0c\u5982\u6709\u9519\u8bef\u6b22\u8fce\u6307\u51fa\uff0c\u8c22\u8c22\uff01\uff01\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f1a\u4e0d\u4f1a\u5199makefile\uff0c\u4ece\u2f00\u4e2a\u4fa7\u2faf\u8bf4\u660e\u4e86\u2f00\u4e2a\u2f08\u662f\u5426\u5177\u5907\u5b8c\u6210\u2f24\u578b\u2f2f\u7a0b\u7684\u80fd\u2f12 \u2f00\u4e2a\u2f2f\u7a0b\u4e2d\u7684\u6e90\u2f42\u4ef6\u4e0d\u8ba1\u6570\uff0c\u5176\u6309\u7c7b\u578b&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":5,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":869,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/869"}],"wp:attachment":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}