{"id":5621,"date":"2023-07-13T12:19:12","date_gmt":"2023-07-13T04:19:12","guid":{"rendered":"https:\/\/www.yimenapp.cn\/yun\/?p=5621"},"modified":"2023-07-13T12:19:12","modified_gmt":"2023-07-13T04:19:12","slug":"golang%e7%94%9f%e6%88%90exe%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenapp.cn\/yun\/2023\/5621\/","title":{"rendered":"golang\u751f\u6210exe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"<p>Golang\u751f\u6210exe\u6587\u4ef6\uff1a\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n<p>Golang\uff0c\u5168\u540dGo\u8bed\u8a00\uff0c\u662f\u4e00\u95e8\u5177\u6709\u9ad8\u6027\u80fd\u548c\u7b80\u6d01\u8bed\u6cd5\u7684\u9759\u6001\u7f16\u8bd1\u578b\u7f16\u7a0b\u8bed\u8a00\u3002\u975e\u5e38\u9002\u5408\u7528\u6765\u7f16\u5199Web\u5e94\u7528\u3001\u5fae\u670d\u52a1\u3001\u5feb\u901f\u539f\u578b\u8bbe\u8ba1\u548c\u811a\u672c\u7b49\u3002\u5728Golang\u4e2d\uff0c\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u975e\u5e38\u7b80\u5355\u3002\u4ee5\u4e0b\u662f\u5173\u4e8e\u5982\u4f55\u751f\u6210.exe\u6587\u4ef6\u7684\u8be6\u7ec6\u4ecb\u7ecd\u548c\u539f\u7406\u9610\u8ff0\u3002<\/p>\n<p>\u4e00\u3001\u539f\u7406\uff1a<\/p>\n<p>\u5f53\u4f7f\u7528Go\u7f16\u8bd1\u7a0b\u5e8f\u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u6210\u673a\u5668\u4ee3\u7801\uff0c\u5e76\u5c06\u5176<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/15\/14\/19287384967.jpg\" \/><\/figure>\n<\/p>\n<p>\u5d4c\u5165\u5230\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u7531\u4e8eGo\u662f\u9759\u6001\u7f16\u8bd1\u7684\u8bed\u8a00\uff0c\u6240\u9700\u7684\u4f9d\u8d56\u90fd\u4f1a\u6253\u5305\u5230\u4e00\u4e2a\u72ec\u7acb\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\uff0c\u751f\u6210\u7684exe\u6587\u4ef6\u4e0d\u4f9d\u8d56\u4e8e\u989d\u5916\u7684DLL\u6216\u8fd0\u884c\u5e93\u3002<\/p>\n<p>\u5728\u5e95\u5c42\uff0cGo\u7f16\u8bd1\u5668\u4f1a\u6839\u636e\u76ee\u6807\u5e73\u53f0\u751f\u6210\u9002\u5f53\u683c\u5f0f\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8eWindows\u7cfb\u7edf\uff0c\u7f16\u8bd1\u5668\u4f1a\u751f\u6210PE\uff08Portable Executable\uff09\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u5373\u6211\u4eec\u901a\u5e38\u770b\u5230\u7684.exe\u6587\u4ef6\u3002<\/p>\n<p>\u4e8c\u3001\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n<p>1. \u7f16\u5199Go\u7a0b\u5e8f<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Go\u7a0b\u5e8f\u4f5c\u4e3a\u793a\u4f8b\u3002\u5c06\u4ee5\u4e0b\u4ee3\u7801\u4fdd\u5b58\u4e3a `main.go`:<\/p>\n<p>&#8220;`go<\/p>\n<p>package main<\/p>\n<p>import &#8220;fmt&#8221;<\/p>\n<p>func main() {<\/p>\n<p>    fmt.Println(&#8220;Hello, World!&#8221;)<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u7f16\u8bd1\u751f\u6210exe\u6587\u4ef6<\/p>\n<p>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u4f7f\u7528Go\u7f16\u8bd1\u5668\uff08go build\uff09\u5c06\u7a0b\u5e8f\u7f16\u8bd1\u6210\u4e00\u4e2a.exe\u6587\u4ef6:<\/p>\n<p>&#8220;`sh<\/p>\n<p>$ go build -o hello_world.exe main.go<\/p>\n<p>&#8220;`<\/p>\n<p>&#8216;-o&#8217;\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u7684\u540d\u79f0\uff0c\u8fd9\u91cc\u6211\u4eec\u5c06\u5176\u547d\u540d\u4e3a`hello_world.exe`\u3002\u5982\u679c\u4e0d\u63d0\u4f9b&#8217;-o&#8217;\u9009\u9879\uff0c\u5219\u9ed8\u8ba4\u8f93\u51fa\u6587\u4ef6\u540d\u4e0e\u6e90\u6587\u4ef6\u540c\u540d\u3002\u8fd0\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0c\u5728\u5de5\u4f5c\u76ee\u5f55\u4e2d\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a `hello_world.exe` \u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>3. \u53ef\u6267\u884c\u6587\u4ef6\u8de8\u5e73\u53f0\u7f16\u8bd1<\/p>\n<p>Go\u7f16\u8bd1\u5668\u8fd8\u652f\u6301\u8de8\u5e73\u53f0\u7f16\u8bd1\uff0c\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u901a\u8fc7\u8bbe\u7f6e`G<a href=\"https:\/\/exe.yimenapp.com\/tool-689.html\">\u505a\u4e00\u4e2a\u684c\u9762\u8f6f\u4ef6<\/a>OOS`\uff08\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\uff09\u548c`GOARCH`\uff08\u76ee\u6807\u67b6\u6784\uff09\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684\u3002\u4f8b\u5982\uff0c\u8981\u4e3aWindows 64\u4f4d\u7cfb\u7edf\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`sh<\/p>\n<p>$ env GOOS=windows GOARCH=amd64 go build -o hello_world.exe main.go<\/p>\n<p>&#8220;`<\/p>\n<p>\u901a\u8fc7\u4fee\u6539`GOOS`\u548c`GOARCH`\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u4e3a\u5176\u4ed6\u5e73\u53f0\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u4e3a\u5176\u4ed6\u5e73\u53f0\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684\u5e93\u5177\u6709\u8de8\u5e73\u53f0\u517c\u5bb9\u6027\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>Golang\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8fc7\u7a0b\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f7f\u7528 `go build` \u547d\u4ee4\u7f16\u8bd1\u76ee\u6807\u7a0b\u5e8f\u5373\u53ef\u3002Go\u7f16\u8bd1\u5668\u8fd8\u652f\u6301\u8de8\u5e73\u53f0\u7f16\u8bd1\uff0c\u4f7f\u7528\u4e0d\u540c\u7684GOOS\u548cGOA<a href=\"https:\/\/www.yimenexe.com\/ruanjian-kaifa-1490.html\">node \u540e\u7aef \u6253\u5305 exe<\/a>RCH\u73af\u5883\u53d8\u91cf\u503c\u5373\u53ef\u751f\u6210\u4e0d\u540c\u5e73\u53f0\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u79cd\u7b80\u5355\u7684\u7f16\u8bd1\u8fc7\u7a0b\u548c\u8de8\u5e73\u53f0\u7f16\u8bd1\u80fd\u529b\u4f7f\u5f97Go\u8bed\u8a00\u6210\u4e3a\u7f16\u5199\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u7406\u60f3\u9009\u62e9\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u7406\u89e3Golang\u751f\u6210exe\u6587\u4ef6\u7684\u539f\u7406\u548c\u8fc7\u7a0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Golang\u751f\u6210exe\u6587\u4ef6\uff1a\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecdGolang\uff0c\u5168\u540dGo\u8bed\u8a00\uff0c\u662f\u4e00\u95e8\u5177\u6709\u9ad8\u6027\u80fd\u548c\u7b80\u6d01\u8bed\u6cd5\u7684\u9759\u6001\u7f16\u8bd1\u578b\u7f16\u7a0b\u8bed\u8a00\u3002\u975e\u5e38\u9002\u5408\u7528\u6765\u7f16\u5199Web\u5e94\u7528\u3001\u5fae\u670d\u52a1\u3001\u5feb\u901f\u539f\u578b\u8bbe\u8ba1\u548c\u811a\u672c\u7b49\u3002\u5728Golang\u4e2d\uff0c\u751f\u6210<\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[10451,539,5279,22,1082],"topic":[],"class_list":["post-5621","post","type-post","status-publish","format-standard","hentry","category-diannaoruanjian","tag-10451","tag-539","tag-5279","tag-22","tag-1082"],"_links":{"self":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/posts\/5621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/comments?post=5621"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/posts\/5621\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/media?parent=5621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/categories?post=5621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/tags?post=5621"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/topic?post=5621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}