{"id":6489,"date":"2023-08-11T12:19:04","date_gmt":"2023-08-11T04:19:04","guid":{"rendered":"https:\/\/app.60day.cn\/appday\/?p=6489"},"modified":"2023-08-11T12:19:04","modified_gmt":"2023-08-11T04:19:04","slug":"golang%e7%94%9f%e6%88%90%e7%9a%84exe%e6%96%87%e4%bb%b6%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84","status":"publish","type":"post","link":"https:\/\/app.60day.cn\/appday\/kaifaexe\/6489\/","title":{"rendered":"golang\u751f\u6210\u7684exe\u6587\u4ef6\u600e\u4e48\u5b9e\u73b0\u7684?"},"content":{"rendered":"<p>**\u6807\u9898\uff1aGolang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd**<\/p>\n<p>Golang\uff08\u4e5f\u79f0\u4e3aGo\u8bed\u8a00\uff09\u662f\u4e00\u79cd\u7f16\u8bd1\u578b\u3001\u9759\u6001\u7c7b\u578b\u3001\u5783\u573e\u56de\u6536\u5f0f\u3001\u5e76\u53d1\u7f16\u7a0b\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u7406\u89e3Golang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u5bf9\u4e8eGo\u7a0b\u5e8f\u5458\u975e\u5e38\u6709\u7528\u3002\u672c\u6587\u5c06\u4e3a\u60a8\u4ecb\u7ecdGolang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406\u3001\u6b65\u9aa4\u53ca\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<p>**\u4e00\u3001Golang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406**<\/p>\n<p>Golang\u662f\u4e00\u79cd\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u8fd9\u610f\u5473\u7740Go\u4ee3\u7801\u4f1a\u88ab\u7f16\u8bd1\u6210\u8ba1\u7b97\u673a\u53ef\u4ee5\u76f4\u63a5\u6267\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\u6587\u4ef6\uff09\u3002Go\u7f16\u8bd1\u5668\u53ef\u4ee5\u5728\u4e00\u4e2a\u5e73\u53f0\u4e0a\u4e3a\u5176\u4ed6\u5e73\u53f0<a href=\"https:\/\/www.yimenexe.com\/ruanjian-kaifa-2658.html\">pytorh\u6253\u5305exe<\/a>\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8fd9\u4f7f\u5f97\u7a0b\u5e8f\u5458\u80fd\u591f\u5f88\u65b9\u4fbf\u5730\u8de8\u5e73\u53f0\u5f00\u53d1\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662fGolang\u751f\u6210EXE\u6587\u4ef6\u7684\u57fa\u672c\u539f\u7406\uff1a<\/p>\n<p>1. \u6e90\u4ee3\u7801\u5206\u6790\uff1aGo\u7f16\u8bd1\u5668\u9996\u5148\u5206\u6790\u6e90\u4ee3\u7801\uff0c\u6784\u5efa\u8bed\u6cd5\u6811\u548c\u62bd\u8c61\u8bed\u6cd5\u6811\uff08AST\uff09\u3002<\/p>\n<p>2. \u4ee3\u7801\u751f\u6210\uff1aGo\u7f16\u8bd1\u5668\u5c06\u62bd\u8c61\u8bed\u6cd5\u6811\u7ffb\u8bd1\u6210\u53ef\u79fb\u690d\u7684\u4f4e\u7ea7\u4ee3\u7801\uff0c\u4f8b\u5982Go\u6c47\u7f16\u4ee3\u7801\u3002<\/p>\n<p>3. \u6c47\u7f16\u4e0e\u94fe\u63a5\uff1aGo\u7f16\u8bd1\u5668\u5c06\u751f\u6210\u7684\u4f4e\u7ea7\u4ee3\u7801\u7f16\u8bd1\u6210\u76ee\u6807\u5e73\u53f0\u7684\u673a\u5668\u8bed\u8a00\uff0c\u5e76\u4e0e\u8fd0\u884c\u65f6\u5e93\uff08\u5305\u542b\u5185\u5b58\u7ba1\u7406\u3001\u5783\u573e\u56de\u6536\u7b49\u529f\u80fd\u7684\u5e93\uff09\u94fe\u63a5\uff0c\u751f\u6210\u6700\u7ec8\u7684EXE\u6587\u4ef6\u3002<\/p>\n<p>**\u4e8c\u3001Golang\u751f\u6210EXE\u6587\u4ef6\u7684\u6b65\u9aa4**<\/p>\n<p>\u751f\u6210Golang EXE\u6587\u4ef6\u7684\u6b65\u9aa4\u5f88\u7b80\u5355\uff0c\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n<p>1. \u7f16\u5199Go\u7a0b\u5e8f\uff1a\u9996\u5148\uff0c\u60a8\u9700\u8981\u7f16\u5199\u4e00\u4e2aGolang\u7a0b\u5e8f\u5e76\u4fdd\u5b58\u4e3a.go\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u53eb\u505amain.go\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542b\u4e00\u4e2a\u57fa\u672c\u7684Hello World\u7a0b\u5e8f\u3002<\/p>\n<p>&#8220;`<\/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. \u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff1a\u5728Windows\u5e73\u53f0\u4e0a\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\uff1b\u5728macOS\u6216Linux\u4e0a\uff0c\u6253\u5f00\u7ec8\u7aef\u3002<\/p>\n<p>3. <\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/28\/13\/01122894170.jpg\" \/><\/figure>\n<\/p>\n<p>\u4f7f\u7528Go\u7f16\u8bd1\u5668\uff1a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\uff0c\u5207\u6362\u5230\u60a8\u7684Go\u7a0b\u5e8f\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>go build -ldflags=&#8221;-s -w&#8221; -o output.exe main.go<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a\u540d\u4e3aoutput.exe\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6b64\u547d\u4ee4\u4e2d\u7684`-ldflags=&#8221;-<a href=\"https:\/\/www.yimenexe.com\/ruanjian-kaifa-2067.html\">python \u53ef\u4ee5\u751f\u6210exe\u4e48<\/a>s -w&#8221;`\u53c2\u6570\u7528\u4e8e\u79fb\u9664\u7b26\u53f7\u8868\u548c\u8c03\u8bd5\u4fe1\u606f\uff0c\u4ee5\u51cf\u5c0f\u751f\u6210\u7684EXE\u6587\u4ef6\u4f53\u79ef\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u6b64\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>.\/output.exe<\/p>\n<p>&#8220;`<\/p>\n<p>\u5728Windows\u4e0a\uff0c\u53cc\u51fboutput.exe\u6587\u4ef6\u4e5f\u53ef\u4ee5\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<p>**\u4e09\u3001\u6ce8\u610f\u4e8b\u9879**<\/p>\n<p>1. \u786e\u4fdd\u5df2\u5b89\u88c5Go\u7f16\u8bd1\u5668\u3002\u4f7f\u7528Go\u5b98\u65b9\u7f51\u7ad9\uff08https:\/\/golang.org\/dl\/ \uff09\u4e0a\u63d0\u4f9b\u7684\u5b89\u88c5\u7a0b\u5e8f\u5b89\u88c5Go\u7f16\u8bd1\u5668\uff0c\u53ca\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>2. Golang\u751f\u6210\u7684EXE\u6587\u4ef6\u4f53\u79ef\u8f83\u5927\uff0c\u8fd9\u662f\u56e0\u4e3a\u5b83\u5305\u542b\u4e86\u6574\u4e2a\u8fd0\u884c\u65f6\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u547d\u4ee4\u4e2d\u63d0\u5230\u7684`-ldflags`\u53c2\u6570\u79fb\u9664\u90e8\u5206\u4fe1\u606f\u6765\u51cf\u5c0f\u6587\u4ef6\u4f53\u79ef\uff0c\u4f46\u56e0\u4e3a\u5305\u542b\u8fd0\u884c\u65f6\u5e93\u7684\u539f\u56e0\uff0c\u6587\u4ef6\u4f53\u79ef\u65e0\u6cd5\u964d\u5f97\u975e\u5e38\u4f4e\u3002<\/p>\n<p>3. Golang\u652f\u6301\u4ea4\u53c9\u7f16\u8bd1\uff0c\u53ef\u4ee5\u5728\u4e00\u4e2a\u5e73\u53f0\u4e0a\u4e3a\u5176\u4ed6\u5e73\u53f0\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5728Linux\u4e0a\u751f\u6210Windows\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u9700\u8981\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>GOOS=windows GOARCH=amd64 go build -ldflags=&#8221;-s -w&#8221; -o output.exe main.go<\/p>\n<p>&#8220;`<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u89e3\u91ca\u4e86Golang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528Golang\u7f16\u5199\u7a0b\u5e8f\u5e76\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u4e86\u3002\u795d\u60a8\u7f16\u7a0b\u6109\u5feb\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>**\u6807\u9898\uff1aGolang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd**Golang\uff08\u4e5f\u79f0\u4e3aGo\u8bed\u8a00\uff09\u662f\u4e00\u79cd\u7f16\u8bd1\u578b\u3001\u9759\u6001\u7c7b\u578b\u3001\u5783\u573e\u56de\u6536\u5f0f\u3001\u5e76\u53d1\u7f16\u7a0b\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u7406\u89e3Golang\u751f\u6210EXE\u6587\u4ef6\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u5bf9\u4e8eGo\u7a0b<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[12011,674,132,7735,1241],"topic":[],"class_list":["post-6489","post","type-post","status-publish","format-standard","hentry","category-kaifaexe","tag-labviewexe","tag-674","tag-132","tag-exe","tag-1241"],"_links":{"self":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/6489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/comments?post=6489"}],"version-history":[{"count":0,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/6489\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/media?parent=6489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/categories?post=6489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/tags?post=6489"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/topic?post=6489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}