{"id":20356,"date":"2024-04-02T15:41:49","date_gmt":"2024-04-02T07:41:49","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=20356"},"modified":"2024-04-02T15:41:49","modified_gmt":"2024-04-02T07:41:49","slug":"windows%e6%89%93%e5%8c%85linux%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/20356\/","title":{"rendered":"windows\u6253\u5305linux\u5982\u4f55\u5b9e\u73b0?"},"content":{"rendered":"

\u5728\u8ba1\u7b97\u673a\u9886\u57df\uff0c\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u7684\u517c\u5bb9\u6027\u4e00\u76f4\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u95ee\u9898\u3002\u5c24\u5176\u662f\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u5019\u9700\u8981\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fdb\u884c\u7f16\u8bd1\u548c\u6253\u5305\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u8003\u8651\u5982\u4f55\u5728\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6253\u5305\u51fa\u53e6\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u53ef\u6267\u884c\u7684\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6253\u5305\u51faLinux\u64cd\u4f5c\u7cfb\u7edf\u53ef\u6267\u884c\u7684\u7a0b\u5e8f\u7684\u539f\u7406\u548c\u65b9\u6cd5\u3002<\/p>\n

1. \u4e86\u89e3\u4ea4\u53c9\u7f16\u8bd1<\/p>\n

\u4ea4\u53c9\u7f16\u8bd1\u662f\u6307\u5728\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7f16\u8bd1\u51fa\u5728\u53e6\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7f16\u8bd1\u51fa\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u4f7f\u7528\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u3002\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u662f\u4e00\u7ec4\u7f16\u8bd1\u5668\u3001\u94feh5\u76f4\u63a5\u6253\u5305\u6210exe<\/a>\u63a5\u5668\u3001\u5e93\u7b49\u5de5\u5177\u7684\u96c6\u5408\uff0c\u8fd9\u4e9b\u5de5\u5177\u80fd\u591f\u5c06\u4ee3\u7801\u7f16\u8bd1\u6210\u5728\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

2. \u5b89\u88c5\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe<\/p>\n

\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u9700\u8981\u6211\u4eec\u5148\u4e86\u89e3\u76ee\u6807Linux\u64cd\u4f5c\u7cfb\u7edf\u7684\u67b6\u6784\u3002\u4f8b\u5982\uff0c\u5982\u679c\u76ee\u6807Linux\u64cd\u4f5c\u7cfb\u7edf\u7684\u67b6\u6784\u662fx86_64\uff0c\u5219\u9700\u8981\u5b89\u88c5\u76f8\u5e94\u7684\u4ea4\u53c9\u7f16\u8bd1html\u5236\u4f5c\u6210exe<\/a>\u5de5\u5177\u94fe\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5047\u8bbe\u76ee\u6807Linux\u64cd\u4f5c\u7cfb\u7edf\u7684\u67b6\u6784\u4e3ax86_64\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e0b\u8f7d\u5e76\u5b89\u88c5MinGW-w64\u3002MinGW-w64\u662f\u4e00\u4e2aWindows\u5e73\u53f0\u4e0b\u7684GNU\u5f00\u53d1\u5de5\u5177\u96c6\uff0c\u5b83\u652f\u6301\u591a\u79cd\u67b6\u6784\u7684\u4ea4\u53c9\u7f16\u8bd1\u3002\u6211\u4eec\u9700\u8981\u4e0b\u8f7d\u5e76\u5b89\u88c5MinGW-w64-x86_64\u5de5\u5177\u96c6\uff0c\u8fd9\u4e2a\u5de5\u5177\u96c6\u5305\u542b\u4e86\u652f\u6301x86_64\u67b6\u6784\u7684\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u3002<\/p>\n

\u5176\u6b21\uff0c\u6211\u4eec\u9700\u8981\u4e0b\u8f7d\u5e76\u5b89\u88c5\u76ee\u6807Linux\u64cd\u4f5c\u7cfb\u7edf\u5bf9\u5e94\u7684\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u4e0b\u8f7d\u5e76\u5b89\u88c5x86_64-linux-gnu\u5de5\u5177\u94fe\u3002\u8fd9\u4e2a\u5de5\u5177\u94fe\u5305\u542b\u4e86\u652f\u6301x86_64\u67b6\u6784\u7684Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7684\u7f16\u8bd1\u5668\u3001\u94fe\u63a5\u5668\u3001\u5e93\u7b49\u5de5\u5177\u3002<\/p>\n

3. \u7f16\u8bd1\u7a0b\u5e8f<\/p>\n

\u5728\u5b89\u88c5\u597d\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f00\u59cb\u7f16\u8bd1\u7a0b\u5e8f\u4e86\u3002\u5047\u8bbe\u6211\u4eec\u9700\u8981\u7f16\u8bd1\u4e00\u4e2a\u7b80\u5355\u7684\u201cHello, World!\u201d\u7a0b\u5e8f\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u201cHello, World!\u201d\u7a0b\u5e8f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u4e00\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u4f8b\u5982C\u8bed\u8a00\u3002<\/p>\n

\u5176\u6b21\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u6765\u7f16\u8bd1\u7a0b\u5e8f\u3002\u5728\u4f7f\u7528\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u7f16\u8bd1\u5668\u3001\u94fe\u63a5\u5668\u7b49\u5de5\u5177\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u5728\u4f7f\u7528x86_64-linux-gnu\u5de5\u5177\u94fe\u7f16\u8bd1C\u7a0b\u5e8f\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

x86_64-linux-gnu-gcc -o hello hello.c<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f7f\u7528x86_64-linux-gnu-gcc\u7f16\u8bd1\u5668\u6765\u7f16\u8bd1hello.c\u6587\u4ef6\uff0c\u5e76\u751f\u6210\u4e00\u4e2a\u540d\u4e3ahello\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

4. \u6253\u5305\u7a0b\u5e8f<\/p>\n

\u5728\u7f16\u8bd1\u597d\u7a0b\u5e8f\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06\u7a0b\u5e8f\u6253\u5305\u6210\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u53ef\u6267\u884c\u6587\u4ef6\u901a\u5e38\u662f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u5b83\u5305\u542b\u4e86\u7a0b<\/p>\n

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

\u5e8f\u7684\u4ee3\u7801\u3001\u6570\u636e\u548c\u5143\u6570\u636e\u7b49\u4fe1\u606f\u3002<\/p>\n

\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528objcopy\u5de5\u5177\u6765\u5c06\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002objcopy\u662f\u4e00\u4e2aGNU\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u6362\u6210\u4e0d\u540c\u683c\u5f0f\u7684\u6587\u4ef6\u3002<\/p>\n

\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u7f16\u8bd1\u597d\u4e86\u4e00\u4e2a\u540d\u4e3ahello\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06hello\u6253\u5305\u6210\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

x86_64-linux-gnu-objcopy -I binary -O elf64-x86-64 -B i386 hello hello.bin<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f7f\u7528x86_64-linux-gnu-objcopy\u5de5\u5177\u5c06hello\u8f6c\u6362\u6210\u4e00\u4e2aELF64\u683c\u5f0f\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u5e76\u5c06\u5b83\u4fdd\u5b58\u5230hello.bin\u6587\u4ef6\u4e2d\u3002<\/p>\n

5. \u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7a0b\u5e8f<\/p>\n

\u5728\u6253\u5305\u597d\u7a0b\u5e8f\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u5b83\u62f7\u8d1d\u5230Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u5e76\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u5b83\u4e86\u3002\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528chmod\u547d\u4ee4\u6765\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6\u6dfb\u52a0\u6267\u884c\u6743\u9650\u3002\u4f8b\u5982\uff0c\u5728\u7ed9hello.bin\u6dfb\u52a0\u6267\u884c\u6743\u9650\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u5b83\uff1a<\/p>\n

“`<\/p>\n

.\/hello.bin<\/p>\n

“`<\/p>\n

\u603b\u7ed3<\/p>\n

\u672c\u6587\u4ecb\u7ecd\u4e86\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6253\u5305Linux\u64cd\u4f5c\u7cfb\u7edf\u53ef\u6267\u884c\u7684\u7a0b\u5e8f\u7684\u539f\u7406\u548c\u65b9\u6cd5\u3002\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u6765\u7f16\u8bd1\u7a0b\u5e8f\uff0c\u5e76\u4f7f\u7528objcopy\u5de5\u5177\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u6253\u5305\u6210\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4e8c\u8fdb\u5236\u6587\u4ef6\u62f7\u8d1d\u5230Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u5e76\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u5b83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u8ba1\u7b97\u673a\u9886\u57df\uff0c\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u7684\u517c\u5bb9\u6027\u4e00\u76f4\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u95ee\u9898\u3002\u5c24\u5176\u662f\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u5019\u9700\u8981\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fdb\u884c\u7f16\u8bd1\u548c\u6253\u5305\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u8003\u8651\u5982\u4f55\u5728\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6253\u5305\u51fa\u53e6\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u53ef\u6267\u884c\u7684\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12621,52,14,22480,89],"topic":[],"class_list":["post-20356","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-webexe","tag-52","tag-14","tag-vueexe","tag-89"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/20356","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\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=20356"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/20356\/revisions"}],"predecessor-version":[{"id":20504,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/20356\/revisions\/20504"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=20356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=20356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=20356"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=20356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}