{"id":5684,"date":"2023-09-25T15:46:07","date_gmt":"2023-09-25T07:46:07","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=5684"},"modified":"2023-09-25T15:46:07","modified_gmt":"2023-09-25T07:46:07","slug":"linux%e5%ba%93%e6%96%87%e4%bb%b6%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/5684\/","title":{"rendered":"linux\u5e93\u6587\u4ef6\u662f\u4ec0\u4e48\u610f\u601d\uff1f"},"content":{"rendered":"

\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u5e93\u6587\u4ef6\u662f\u4e00\u79cd\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u6a21\u5757\uff0c\u5b83\u5305\u542b\u4e86\u4e00\u7ec4\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5458\u7528\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecdLinux\u5e93\u6587\u4ef6\u7684\u539f\u7406\u548c\u76f8\u5173\u77e5\u8bc6\u3002<\/p>\n

\u4e00\u3001\u5e93\u6587\u4ef6\u7684\u6982\u5ff5<\/p>\n

\u5e93\u6587\u4ef6\u662f\u4e00\u79cd\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u6a21\u5757\uff0c\u5b83\u5305\u542b\u4e86\u4e00\u7ec4\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5458\u7528\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u5e93\u6587\u4ef6\u53efzao\u878d\u5408\u751f\u6210\u7684\u8f6f\u4ef6<\/a>\u4ee5\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1a\u9759\u6001\u5e93\u548c\u52a8\u6001\u5e93\u3002\u9759\u6001\u5e93\u662f\u5728\u7f16\u8bd1\u65f6\u88ab\u94fe\u63a5\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\u7684\uff0c\u800c\u52a8\u6001\u5e93\u662f\u5728\u8fd0\u884c\u65f6\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u7684\u3002<\/p>\n

\u4e8c\u3001\u9759\u6001\u5e93<\/p>\n

\u9759\u6001\u5e93\u662f\u4e00\u79cd\u88ab\u7f16\u8bd1\u6210\u76ee\u6807\u6587\u4ef6\u7684\u5e93\u6587\u4ef6\uff0c\u5b83\u5305\u542b\u4e86\u4e00\u7ec4\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5458\u7528\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u9759\u6001\u5e93\u5728\u7f16\u8bd1\u65f6\u88ab\u94fe\u63a5\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u56e0\u6b64\u9759\u6001\u5e93\u7684\u4ee3\u7801\u88ab\u590d\u5236\u5230\u4e86\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u5f97\u76ee\u6807\u7a0b\u5e8f\u53d8\u5f97\u66f4\u5927\u3002<\/p>\n

\u9759\u6001\u5e93\u7684\u4f18\u70b9\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4e0d\u9700\u8981\u52a0\u8f7d\u5e93\u6587\u4ef6\uff0c\u56e0\u6b64\u53ef\u4ee5\u51cf\u5c11\u7cfb\u7edf\u5f00\u9500\u3002\u6b64\u5916\uff0c\u9759\u6001\u5e93\u7684\u4ee3\u7801\u53ef\u4ee5\u88ab\u7f16\u8bd1\u5668\u4f18\u5316\uff0c\u56e0\u6b64\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u9759\u6001\u5e93\u7684\u7f3a\u70b9\u662f\u76ee\u6807\u7a0b\u5e8f\u53d8\u5f97\u66f4\u5927\uff0c\u56e0\u6b64\u4f1a\u5360\u7528\u66f4\u591a\u7684\u78c1\u76d8\u7a7a\u95f4\u3002<\/p>\n

\u4e09\u3001\u52a8\u6001\u5e93<\/p>\n

\u52a8\u6001\u5e93\u662f\u4e00\u79cd\u5728\u8fd0\u884c\u65f6\u88ab\u52a0\u8f7d\u7684\u5e93\u6587\u4ef6\uff0c\u5b83\u5305\u542b\u4e86\u4e00\u7ec4\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5458\u7528\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u52a8\u6001\u5e93\u7684\u4ee3\u7801\u4e0d\u4f1a\u88ab\u590d\u5236\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u56e0\u6b64\u76ee\u6807\u7a0b\u5e8f\u7684\u5927\u5c0f\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\u3002<\/p>\n

\u52a8\u6001\u5e93\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u56e0\u6b64\u53ef\u4ee5\u8282\u7701\u7cfb\u7edf\u8d44\u6e90\u3002\u6b64\u5916\uff0c\u52a8\u6001\u5e93\u7684\u4ee3\u7801\u53ef\u4ee5\u88ab\u66f4\u65b0\uff0c\u56e0\u6b64\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u52a8\u6001\u5e93\u7684\u7f3a\u70b9\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u9700\u8981\u52a0\u8f7d\u5e93\u6587\u4ef6\uff0c\u56e0\u6b64\u4f1a\u589e\u52a0\u7cfb\u7edf\u5f00\u9500\u3002\u6b64\u5916\uff0c\u52a8\u6001\u5e93\u7684\u4ee3\u7801\u4e0d\u80fd\u88ab\u7f16\u8bd1\u5668\u4f18\u5316\uff0c\u56e0\u6b64\u53ef\u80fd\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/p>\n

\u56db\u3001\u5e93\u6587\u4ef6\u7684\u4f7f\u7528<\/p>\n

\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u5e93\u6587\u4ef6\u7684\u4f7f\u7528\u5206\u4e3a\u4e24\u79cd\u65b9\u5f0f\uff1a\u9759\u6001\u94fe\u63a5\u548c\u52a8\u6001\u94fe\u63a5\u3002\u9759\u6001\u94fe\u63a5\u662f\u5c06\u5e93\u6587\u4ef6\u7684\u4ee3\u7801\u590d\u5236\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u56e0\u6b64\u76ee\u6807\u7a0b\u5e8f\u53ef\u4ee5\u72ec\u7acb\u8fd0\u884c\u3002\u52a8\u6001\u94fe\u63a5\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u52a0\u8f7d\u5e93\u6587\u4ef6\uff0c\u56e0\u6b64\u53ef\u4ee5\u8282\u7701\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n

\u9759\u6001\u94fe\u63a5\u7684\u65b9\u5f0f\u662f\u5728\u7f16\u8bd1\u65f6\u5c06\u5e93\u6587\u4ef6\u94fe\u63a5\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

`beet\u5236\u4f5c\u8f6f\u4ef6<\/a>“<\/p>\n

gcc -o program program.c libxxx.a<\/p>\n

“`<\/p>\n

\u52a8\u6001\u94fe\u63a5\u7684\u65b9\u5f0f\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u52a0\u8f7d\u5e93\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

gcc -o program program.c -lxxx<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c-l\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u8981\u94fe\u63a5\u7684\u5e93\u6587\u4ef6\uff0c\u4f8b\u5982-lm\u8868\u793a\u94fe\u63a5\u6570\u5b66\u5e93\u6587\u4ef6libm.so\u3002<\/p>\n

\u4e94\u3001\u5e93\u6587\u4ef6\u7684\u5236\u4f5c<\/p>\n

\u5236\u4f5c\u5e93\u6587\u4ef6\u9700\u8981\u4f7f\u7528\u7f16\u8bd1\u5668\u548c\u94fe\u63a5\u5668\u3002\u9996\u5148\uff0c\u9700\u8981\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u6210\u76ee\u6807\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<\/p>\n

“`<\/p>\n

gcc -c library.c<\/p>\n

“`<\/p>\n

\u7136\u540e\uff0c\u9700\u8981\u5c06\u76ee\u6807\u6587\u4ef6\u6253\u5305\u6210\u9759\u6001\u5e93\u6587\u4ef6\u6216\u52a8\u6001\u5e93\u6587\u4ef6\u3002\u9759\u6001\u5e93\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

ar rcs liblibrary.a library.o<\/p>\n

“`<\/p>\n

\u52a8\u6001\u5e93\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d<\/p>\n

<\/figure>\n<\/p>\n

\u4ee4\uff1a<\/p>\n

“`<\/p>\n

gcc -shared -o liblibrary.so library.o<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c-shared\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u751f\u6210\u52a8\u6001\u5e93\u6587\u4ef6\u3002<\/p>\n

\u516d\u3001\u603b\u7ed3<\/p>\n

Linux\u5e93\u6587\u4ef6\u662f\u4e00\u79cd\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u6a21\u5757\uff0c\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5458\u7528\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u5e93\u6587\u4ef6\u5206\u4e3a\u9759\u6001\u5e93\u548c\u52a8\u6001\u5e93\u4e24\u79cd\u7c7b\u578b\uff0c\u9759\u6001\u5e93\u5728\u7f16\u8bd1\u65f6\u88ab\u94fe\u63a5\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u800c\u52a8\u6001\u5e93\u5728\u8fd0\u884c\u65f6\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u5e93\u6587\u4ef6\u7684\u4f7f\u7528\u53ef\u4ee5\u5206\u4e3a\u9759\u6001\u94fe\u63a5\u548c\u52a8\u6001\u94fe\u63a5\u4e24\u79cd\u65b9\u5f0f\u3002\u5236\u4f5c\u5e93\u6587\u4ef6\u9700\u8981\u4f7f\u7528\u7f16\u8bd1\u5668\u548c\u94fe\u63a5\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u5e93\u6587\u4ef6\u662f\u4e00\u79cd\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u6a21\u5757\uff0c\u5b83\u5305\u542b\u4e86\u4e00\u7ec4\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u88ab\u7a0b\u5e8f\u5458\u7528\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecdLinux\u5e93\u6587\u4ef6\u7684\u539f\u7406\u548c\u76f8\u5173\u77e5\u8bc6\u3002\u4e00\u3001\u5e93\u6587\u4ef6\u7684\u6982\u5ff5\u5e93\u6587\u4ef6\u662f\u4e00\u79cd\u53ef\u91cd\u7528<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[10540,16,89,10541,6092],"topic":[],"class_list":["post-5684","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-h5layuiexe","tag-16","tag-89","tag-10541","tag-6092"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/5684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=5684"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/5684\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=5684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=5684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=5684"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=5684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}