{"id":288947,"date":"2023-12-16T05:08:47","date_gmt":"2023-12-15T21:08:47","guid":{"rendered":"https:\/\/lrxjmw.cn\/lcxyzyljmqdh.html"},"modified":"2023-12-16T05:08:47","modified_gmt":"2023-12-15T21:08:47","slug":"lcxyzyljmqdh","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lcxyzyljmqdh.html","title":{"rendered":"Linux C\u7a0b\u5e8f\u8fd0\u4f5c\u539f\u7406\u63ed\u79d8\uff1a\u4e03\u5927\u73af\u8282\u6df1\u5ea6\u89e3\u8bfb"},"content":{"rendered":"

\u656c\u8bf7\u5173\u6ce8\u6211\u4eec\u4eca\u65e5\u7684\u7279\u522b\u62a5\u9053\uff0c\u8be6\u7ec6\u89e3\u8bfbLinux<\/a>\u64cd\u4f5c\u7cfb\u7edf<\/a>\u4e2dC\u7a0b\u5e8f\u7684\u8fd0\u4f5c\u539f\u7406\uff0c\u5e26\u60a8\u6df1\u5ea6\u6d1e\u5bdf\u5176\u5185\u6838\u8fd0\u884c\u6a21\u5f0f\u3002\u4e0d\u7528\u62c5\u5fe7\uff0c\u6587\u7ae0\u529b\u6c42\u4ee5\u6d45\u663e\u6613\u61c2\u7684\u65b9\u5f0f\u8bb2\u89e3\u7ed9\u5927\u5bb6\u542c\u3002\u73b0\u5728\uff0c\u5c31\u8ba9\u6211\u4eec\u4e00\u8d77\u5f00\u59cb\u63a2\u7d22\u5427\uff01<\/p>\n

\u672c\u7bc7\u6587\u7ae0\u9686\u91cd\u9610\u8ff0\u4e86Linux\u73af\u5883\u4e0bC\u4ee3\u7801\u8fd0\u8f6c\u7684\u5168\u8fc7\u7a0b\uff0c\u5e76\u5728\u4ee5\u4e0b\u4e03\u5927\u73af\u8282\u8fdb\u884c\u6df1\u5ea6\u89e3\u8bfb\u3002<\/p>\n

1.\u7f16\u5199C\u7a0b\u5e8f<\/b><\/p>\n

\u9996\u5148\uff0c\u8bf7\u5141\u8bb8\u6211\u4e3a\u60a8\u642d\u5efa\u4e00\u4e2a\u7b80\u5355\u7684C\u7a0b\u5e8f\u4e3a\u4f8b\u3002\u8bd5\u60f3\u4e00\u4e0b\uff0c\u5047\u5982\u6211\u4eec\u6253\u7b97\u7f16\u5236\u4e00\u6bb5\u7a0b\u5e8f\u6765\u6c42\u89e3\u4e24\u4e2a\u6570\u76ee\u7684\u603b\u548clinux \u865a\u62df\u4e3b\u673a\uff0c\u6211\u4eec\u600e\u53ef\u6309\u4e0b\u5462\uff1f\u5b9e\u9645\u4e0alinux\u5982\u4f55\u6267\u884cc\u7a0b\u5e8f<\/strong>\uff0c\u53ea\u7528\u6253\u5f00\u4efb\u4f55\u4e00\u6b3e\u6587\u672c\u7f16\u8f91\u8f6f\u4ef6linux\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u6bd4\u5982\u60a8\u5e38\u7528\u7684\u90a3\u6b3e\uff0c\u5c06\u5176\u547d\u540d\u4e3a\"sum.c\",\u7136\u540e\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u5199\u5165\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n

\n

c\n#include <stdio.h>\nint main(){\n    int a = 10;\n    int b = 20;\n    int sum = a +b;\n\"\u603b\u548c\u4e3a:%d\uff0c\u611f\u8c22\u914d\u5408\uff01\"linux\u5982\u4f55\u6267\u884cc\u7a0b\u5e8f<\/strong>\uff0c\u8f93\u51fa\u603b\u548c\u3002\n    return 0;\n<\/pre>\n<\/p>\n

2.\u9884\u5904\u7406<\/b><\/p>\n

\u5728\u8fdb\u5165\u6b63\u5f0f\u7f16\u8bd1\u9636\u6bb5\u524d\uff0c\u6211\u4eec\u9996\u5148\u8981\u505a\u7684\u5c31\u662f\u9884\u5904\u7406\u5de5\u4f5c\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4e3b\u8981\u4f9d\u636e\u4ee3\u7801\u91cc\u7684\u9884\u5904\u7406\u6307\u4ee4\u6765\u6267\u884c\u76f8\u5173\u4efb\u52a1\u3002\u518d\u5f3a\u8c03\u4e0b\uff0c\u5728Linux\u7cfb\u7edf\u5185\uff0c\u8fd9\u4e9b\u6307\u4ee4\u90fd\u662f\u4ee5“#”\u5b57\u7b26\u4f5c\u4e3a\u8d77\u59cb\u6807\u5fd7\u7684\u54e6\u3002<\/p>\n

\u9884\u5904\u7406\u5668\u4f1a\u7ec6\u5fc3\u5730\u5c06\u5934\u6587\u4ef6\u5982`stdio.h'\u91cc\u7684\u4fe1\u606f\u642c\u8fc1\u5230\u6e90\u6587\u4ef6\u4e2d\uff0c\u5e76\u5b8c\u6210\u8bf8\u5982\u5b8f\u5b9a\u4e49\u7b49\u4efb\u52a1\uff0c\u786e\u4fdd\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u7684\u51fd\u6570\u4e0e\u53d8\u91cf\u80fd\u88ab\u7cbe\u786e\u5730\u627e\u5230\u3002<\/p>\n

3.\u7f16\u8bd1<\/b><\/p>\n

\u73b0\u5728\u6211\u4eec\u8fdb\u5165\u7f16\u8bd1\u73af\u8282\u4e86\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5373\u5c06\u6e90\u4ee3\u7801\u8f6c\u6210\u673a\u5668\u53ef\u4ee5\u7406\u89e3\u7684\u6c47\u7f16\u4ee3\u7801\u3002\u5728Linux\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u901a\u5e38\u90fd\u4f7f\u7528\u5230 gcc\u8fd9\u4e00\u5f3a\u5927\u7684 C \u7f16\u8bd1\u5de5\u5177\u6765\u5b9e\u73b0\u6b64\u529f\u80fd\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4<\/a>\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u4e3a\u6c47\u7f16\u4ee3\u7801\uff1a<\/p>\n

gcc -S sum.c<\/p>\n

linux\u5982\u4f55\u6267\u884cc\u7a0b\u5e8f_\u6267\u884c\u7a0b\u5e8f\u7684\u8fc7\u7a0b_\u6267\u884c\u7a0b\u5e8f\u96f6\u63a7\u63aa\u65bd<\/p>\n

\u8be5\u547d\u4ee4\u5c06\u751f\u6210\u4e00\u4e2a\u540d\u4e3asum.s\u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6c47\u7f16\u4ee3\u7801\u3002<\/p>\n

4.\u6c47\u7f16<\/b><\/p>\n

\u5728\u6b64\u9636\u6bb5\uff0c\u60a8\u7684\u7f16\u8bd1\u5668\u4f1a\u7cbe\u5fc3\u5730\u628a\u6c47\u7f16\u7f16\u7a0b\u8f6c\u6362\u6210\u76f4\u63a5\u4e3a\u8ba1\u7b97\u673a\u6240\u7406\u89e3\u548c\u8fd0\u884c\u7684\u673a\u5668\u7801\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u6c47\u7f16\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u7801\uff1a<\/p>\n

gcc -c sum.s<\/p>\n

\u606d\u559c\u60a8\u6210\u529f\u751f\u6210\u4e86\u540d\u4e3asum.o\u7684\u76ee\u6807\u6587\u4ef6\uff0c\u5176\u4e2d\u8f7d\u6709\u673a\u5668\u7801\u54e6\uff01<\/p>\n

5.\u94fe\u63a5<\/b><\/p>\n

\u94fe\u63a5\u8fc7\u7a0b\u5c31\u662f\u8981\u628a\u7a0b\u5f0f\u5185\u7684\u6240\u6709\u90e8\u5206\uff08\u6bd4\u5982\u51fd\u6570\u5e93\uff09\u6709\u673a\u6574\u5408\u8d77\u6765\uff0c\u5236\u4f5c\u51fa\u4e00\u4e2a\u5b8c\u6574\u53ef\u7528\u7684\u53ef\u6267\u884c\u6587\u4ef6\u54e6\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u94fe\u63a5\uff1a<\/p>\n

gcc -o sum sum.o<\/p>\n

\u8be5\u547d\u4ee4\u5c06\u751f\u6210\u4e00\u4e2a\u540d\u4e3asum\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

6.\u8fd0\u884c<\/b><\/p>\n

\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd0\u884c\u7a0b\u5e8f\u4e86\uff01\u53ea\u9700\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\uff1a<\/p>\n

.\/sum<\/p>\n

\u60a8\u5c06\u770b\u5230\u8f93\u51fa\u7ed3\u679c\uff1a“The sum is: 30”\u3002<\/p>\n

7.\u8c03\u8bd5<\/b><\/p>\n

\u8c03\u8bd5\u4e43\u7cfb\u7edf\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u5173\u952e\u73af\u8282\u3002Linux\u7cfb\u7edf\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5982GDB\u7b49\u529f\u80fd\u5f3a\u5927\u7684\u8c03\u8bd5\u5de5\u5177\u6709\u5229\u5f0a\u3002<\/p>\n

\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u8c03\u8bd5\uff1a<\/p>\n

gdb sum<\/p>\n

\u5982\u6b64\u4e00\u6765\uff0c\u60a8\u53ef\u9010\u884c\u5ba1\u67e5\u4ee3\u7801\uff0c\u8bbe\u4e0a\u65ad\u70b9\u68c0\u67e5\u53d8\u91cf\u6570\u503c\u53d8\u52a8\uff0c\u65b9\u4fbf\u63a2\u7d22\u548c\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n

\u5728\u6b64\u7bc7\u6587\u7ae0\u4e2d\uff0c\u8ba9\u6211\u4eec\u5171\u540c\u63a2\u8ba8\u4e86Linux\u73af\u5883\u4e0bC\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u3002\u5e0c\u671b\u5927\u5bb6\u5728\u9605\u8bfb\u6b64\u6587\u540e\uff0c\u5bf9\u4e8eLinux\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u5728\u8fd0\u4f5c\u65b9\u5f0f\u6709\u66f4\u6df1\u5c42\u6b21\u7684\u7406\u89e3\u3002\u5728\u6b64\u8868\u793a\u6df1\u6df1\u7684\u8c22\u610f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u656c\u8bf7\u5173\u6ce8\u6211\u4eec\u4eca\u65e5\u7684\u7279\u522b\u62a5\u9053\uff0c\u8be6\u7ec6\u89e3\u8bfbLinux\u64cd\u4f5c\u7cfb\u7edf\u4e2dC\u7a0b\u5e8f\u7684\u8fd0\u4f5c\u539f\u7406\uff0c\u5e26\u60a8\u6df1\u5ea6\u6d1e\u5bdf\u5176\u5185\u6838\u8fd0\u884c\u6a21\u5f0f\u3002\u672c\u7bc7\u6587\u7ae0\u9686\u91cd\u9610\u8ff0\u4e86Linux\u73af\u5883\u4e0bC\u4ee3\u7801\u8fd0\u8f6c\u7684\u5168\u8fc7\u7a0b\uff0c\u5e76\u5728\u4ee5\u4e0b\u4e03\u5927\u73af\u8282\u8fdb\u884c\u6df1\u5ea6\u89e3\u8bfb\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4e3b\u8981\u4f9d\u636e\u4ee3\u7801\u91cc\u7684\u9884\u5904\u7406\u6307\u4ee4\u6765\u6267\u884c\u76f8\u5173\u4efb\u52a1\u3002\u5728\u6b64\u7bc7\u6587\u7ae0\u4e2d\uff0c\u8ba9\u6211\u4eec\u5171\u540c\u63a2\u8ba8\u4e86Linux\u73af\u5883\u4e0bC\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u3002<\/p>\n","protected":false},"author":1,"featured_media":288948,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-288947","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/288947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=288947"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/288947\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/288948"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=288947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=288947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=288947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}