{"id":6021,"date":"2023-09-28T15:45:53","date_gmt":"2023-09-28T07:45:53","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=6021"},"modified":"2023-09-28T15:45:53","modified_gmt":"2023-09-28T07:45:53","slug":"linux%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/6021\/","title":{"rendered":"linux\u751f\u6210exe\u6587\u4ef6\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"

\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u5e38\u89c1\u7684\u53ef\u6267\u884c\u6587\u4ef6\u683c\u5f0f\u4e3a ELF\uff08Executable and Linkable Format\uff09\uff0c\u5b83\u662f\u4e00\u79cd\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\u3001\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5171\u4eab\u5e93\u548c\u6838\u5fc3\u8f6c\u50a8\u6587\u4ef6\u7684\u6807\u51c6\u683c\u5f0f\u3002\u4e0e Windows \u7cfb\u7edf\u4e2d\u7684 PE\uff08Portable Executable\uff09\u683c\u5f0f\u4e0d\u540c\uff0cLinux \u5e76\u6ca1\u6709\u76f4\u63a5\u652f\u6301\u751f\u6210 exe \u683c\u5f0f\u7684\u5de5\u5177\u3002\u4e0dexe\u8f6c\u6210dmg<\/a>\u8fc7\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u4e00\u4e9b\u5de5\u5177\u548c\u6280\u5de7\u6765\u5b9e\u73b0\u5728 Linux \u7cfb\u7edf\u4e2d\u751f\u6210 exe \u683c\u5f0f\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u6765\u4ecb\u7ecd\u4e00\u4e0b\u751f\u6210 exe \u6587\u4ef6\u7684\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n

1. \u4f7f\u7528 Wine \u5de5\u5177<\/p>\n

Wine \u662f\u4e00\u4e2a\u80fd\u591f\u5728 Linux \u548c\u5176\u4ed6 POSIX \u517c\u5bb9\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c Windows \u7a0b\u5e8f\u7684\u517c\u5bb9\u5c42\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Wine \u5de5\u5177\u6765\u5c06 Linux \u4e0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u6362\u4e3a Windows \u4e0b\u7684 exe \u683c\u5f0f\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\u7b2c\u4e00\u6b65\uff0c\u5b89\u88c5 Wine \u5de5\u5177\u3002<\/p>\n

\u5728 Ubuntu \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

sudo apt-get install wine<\/p>\n

“`<\/p>\n

\u7b2c\u4e8c\u6b65\uff0c\u7f16\u8bd1\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 gcc \u6216 g++ \u7f16\u8bd1\u5668\u6765\u7f16\u8bd1 C\/C++ \u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u6211<\/p>\n

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

\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a `hello.c` \u7684 C \u8bed\u8a00\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u4e1c\u98ceexe<\/a>\u8bd1\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a `hello` \u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u7b2c\u4e09\u6b65\uff0c\u4f7f\u7528 Wine \u5de5\u5177\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u6362\u4e3a exe \u683c\u5f0f\u3002<\/p>\n

\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u6362\u4e3a exe \u683c\u5f0f\uff1a<\/p>\n

“`<\/p>\n

winegcc -o hello.exe hello<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a `hello.exe` \u7684 Windows \u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

2. \u4f7f\u7528 mingw-w64 \u5de5\u5177\u94fe<\/p>\n

mingw-w64 \u662f\u4e00\u4e2a\u5728 Linux \u548c Windows \u7cfb\u7edf\u4e0b\u90fd\u53ef\u4ee5\u4f7f\u7528\u7684\u5de5\u5177\u94fe\uff0c\u5b83\u53ef\u4ee5\u751f\u6210 Windows \u4e0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\u7b2c\u4e00\u6b65\uff0c\u5b89\u88c5 mingw-w64 \u5de5\u5177\u94fe\u3002<\/p>\n

\u5728 Ubuntu \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

sudo apt-get install mingw-w64<\/p>\n

“`<\/p>\n

\u7b2c\u4e8c\u6b65\uff0c\u7f16\u8bd1\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 gcc \u6216 g++ \u7f16\u8bd1\u5668\u6765\u7f16\u8bd1 C\/C++ \u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a `hello.c` \u7684 C \u8bed\u8a00\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\uff1a<\/p>\n

“`<\/p>\n

x86_64-w64-mingw32-gcc -o hello.exe hello.c<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a `hello.exe` \u7684 Windows \u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5728 Linux \u7cfb\u7edf\u4e2d\u751f\u6210 exe \u683c\u5f0f\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528 Wine \u5de5\u5177\u53ef\u4ee5\u5c06 Linux \u4e0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u6362\u4e3a Windows \u4e0b\u7684 exe \u683c\u5f0f\uff0c\u800c\u4f7f\u7528 mingw-w64 \u5de5\u5177\u94fe\u5219\u53ef\u4ee5\u76f4\u63a5\u751f\u6210 Windows \u4e0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5176\u4e2d\uff0cmingw-w64 \u5de5\u5177\u94fe\u66f4\u4e3a\u65b9\u4fbf\uff0c\u4f46\u9700\u8981\u5b89\u88c5\u989d\u5916\u7684\u5de5\u5177\u94fe\uff1b\u800c\u4f7f\u7528 Wine \u5de5\u5177\u5219\u4e0d\u9700\u8981\u5b89\u88c5\u989d\u5916\u7684\u5de5\u5177\u94fe\uff0c\u4f46\u9700\u8981\u5728\u751f\u6210 exe \u6587\u4ef6\u540e\u5728 Windows \u73af\u5883\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u5e38\u89c1\u7684\u53ef\u6267\u884c\u6587\u4ef6\u683c\u5f0f\u4e3a ELF\uff08Executable and Linkable Format\uff09\uff0c\u5b83\u662f\u4e00\u79cd\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\u3001\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5171\u4eab\u5e93\u548c\u6838\u5fc3\u8f6c\u50a8\u6587\u4ef6\u7684\u6807\u51c6\u683c\u5f0f\u3002\u4e0e Wind<\/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":[256,11093,52,298,11092],"topic":[],"class_list":["post-6021","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-256","tag-yumrpm","tag-52","tag-298","tag-exe"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/6021","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=6021"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/6021\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=6021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=6021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=6021"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=6021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}