{"id":5050,"date":"2023-09-01T12:18:54","date_gmt":"2023-09-01T04:18:54","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=5050"},"modified":"2023-09-01T12:18:54","modified_gmt":"2023-09-01T04:18:54","slug":"golang%e6%89%93%e5%8c%85exe%e6%8a%80%e6%9c%af%e5%8e%9f%e7%90%86%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/09\/01\/golang%e6%89%93%e5%8c%85exe%e6%8a%80%e6%9c%af%e5%8e%9f%e7%90%86%e4%bb%8b%e7%bb%8d\/","title":{"rendered":"golang\u6253\u5305exe\u6280\u672f\u539f\u7406\u4ecb\u7ecd"},"content":{"rendered":"

### Golang\u6253\u5305exe: \u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n

Golaexe\u5355\u6587\u4ef6\u5236\u4f5c\u5de5\u5177<\/a>ng \u662f\u4e00\u95e8\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4f7f\u7528\u5176\u7f16\u8bd1\u5668\uff08\u5982\uff1ago build\uff09\u5c06\u4ee3\u7801\u7f16\u8bd1\u4e3a\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7136\u540e\u5728\u76ee\u6807\u7cfb\u7edf\u4e0a\u76f4\u63a5\u8fd0\u884c\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u5982\u4f55\u5728 Golang \u4e2d\u521b\u5efa Windows \u53ef\u6267\u884c\u6587\u4ef6\uff08\u5373 exe \u6587\u4ef6\uff09\u3002<\/p>\n

#### \u4ec0\u4e48\u662fexe\u6587\u4ef6\uff1f<\/p>\n

exe \u6587\u4ef6\uff08\u53ef\u6267\u884c\u6587\u4ef6\uff09\u662f\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u6587\u4ef6\uff0c\u7528\u4e8e\u5b58\u50a8\u76f8\u5173\u6267\u884c\u7a0b\u5e8f\u3002\u5f53\u7528\u6237\u53cc\u51fb exe \u6587\u4ef6\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u8d1f\u8d23\u89e3\u6790\u6587\u4ef6\u5e76\u8fd0\u884c\u7a0b\u5e8f\u3002\u5728 Windows \u7cfb\u7edf\u4e2d\uff0c\u7528\u4e8e\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u7684\u6587\u4ef6\u683c\u5f0f\u4e3a Portable Executable (PE)\u3002Golang \u63d0\u4f9b\u4e86\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u4e3a Windows \u53ef\u6267\u884c\u6587\u4ef6\u7684\u529f\u80fd\u3002<\/p>\n

#### Golang\u4e2d\u521b\u5efa Windows \u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

\u4ee5\u4e0b\u662f\u5c06 Golang \u4ee3\u7801\u7f16\u8bd1\u4e3a exe \u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n

1. \u9996\u5148\uff0c\u786e\u4fdd\u5df2\u6210\u529f\u5b89\u88c5 Golang\u3002\u53ef\u4ee5\u5728 Golang \u5b98\u7f51\uff08https:\/\/golang.org\/dl\/ \uff09\u4e0a\u4e0b\u8f7d\u5e76\u5b89\u88c5\u5bf9\u5e94\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 Golang \u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a`hello-world.go`\u7684\u6587\u4ef6\u5e76\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

func main() {<\/p>\n

fmt.Println(“Hello, World!”)<\/p>\n

}<\/p>\n

“`<\/p>\n

3. \u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u7136\u540e\u5bfc\u822a\u5230\u5305\u542b`hello-world.go`\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/p>\n

4. \u4f7f<\/p>\n

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

\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u7f16\u8bd1 Golang \u7a0b\u5e8f\uff0c\u751f\u6210\u4e00\u4e2a\u540d\u4e3a`hello-world.exe`\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

go build -o hello-world.exe hello-world.go<\/p>\n

“`<\/p>\n

\u6b64\u547d\u4ee4\u7684\u53c2\u6570\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n

– `go build`\uff1aGolang \u547d\u4ee4\u884c\u5de5\u5177\u7528\u4e8e\u7f16\u8bd1\u6e90\u4ee3\u7801\u3002<\/p>\n

– `-o hello-world.exe`\uff1a\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u540d\u3002\u8fd9\u91cc\u6211\u4eec\u9009\u5b9a`hello-world.exe`\u4f5c\u4e3a\u8f93\u51fa\u6587\u4ef6\u3002<\/p>\n

– `hello-world.go`\uff1a\u6e90\u4ee3\u7801\u6587\u4ef6\u540d\u79f0\u3002<\/p>\n

5. \u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u76ee\u5f55\u4e2d\u627e\u5230`hello-world.exe`\u6587\u4ef6\u3002\u53cc\u51fb\u6b64\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5373\u53ef\u8fd0\u884c\u7a0b\u5e8f\u5e76\u5728\u7ec8\u7aef\u7a97\u53e3\u4e2d\u770b\u5230 “Hello, World!” \u7684\u8f93\u51fa\u3002<\/p>\n

#### \u5982\u4f55\u4e3a\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u521b\u5efa Windows \u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/p>\n

Golang \u652f\u6301\u4ea4pycharm\u5c01\u88c5exe\u6587\u4ef6<\/a>\u53c9\u7f16\u8bd1\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u4e3a\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u521b\u5efa\u5355\u72ec\u7684\u7a0b\u5e8f\u3002\u8981\u5728\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\uff08\u5982 macOS \u6216 Linux\uff09\u4e0a\u4e3a Windows \u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n

1. \u8ddf\u968f\u4e0a\u8ff0\u90e8\u5206\u4e2d\u201c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 Golang \u7a0b\u5e8f\u201d\u7684\u6b65\u9aa4\u3002<\/p>\n

2. \u6253\u5f00\u7ec8\u7aef\uff0c\u7136\u540e\u5bfc\u822a\u5230\u5305\u542b`hello-world.go`\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/p>\n

3. \u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u8868\u793a\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u4e3a Windows \u64cd\u4f5c\u7cfb\u7edf\u4e0b\u7684 exe \u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

GOOS=windows GOARCH=amd64 go build -o hello-world.exe hello-world.go<\/p>\n

“`<\/p>\n

\u4ee5\u4e0a\u547d\u4ee4\u7684\u53c2\u6570\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n

– `GOOS=windows`\uff1a\u8bbe\u7f6e\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\u4e3a Windows\u3002<\/p>\n

– `GOARCH=amd64`\uff1a\u8bbe\u7f6e\u76ee\u6807\u7cfb\u7edf\u67b6\u6784\u4e3a AMD64\uff0864 \u4f4d\uff09\u3002\u82e5\u76ee\u6807\u7cfb\u7edf\u4e3a 32 \u4f4d\uff0c\u8bf7\u8bbe\u7f6e\u4e3a`GOARCH=386`\u3002<\/p>\n

– `go build`: \u4e0e\u524d\u8ff0\u76f8\u540c\uff0c\u7528\u4e8e\u7f16\u8bd1\u6e90\u4ee3\u7801\u3002<\/p>\n

– `-o hello-world.exe`\uff1a\u4e0e\u524d\u8ff0\u76f8\u540c\uff0c\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u540d\u3002<\/p>\n

– `hello-world.go`\uff1a\u6e90\u4ee3\u7801\u6587\u4ef6\u540d\u79f0\u3002<\/p>\n

\u73b0\u5728\u5df2\u6210\u529f\u751f\u6210\u53ef\u5728 Windows \u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u79cd\u8de8\u5e73\u53f0\u7f16\u8bd1\u529f\u80fd\u4f7f Golang \u6210\u4e3a\u6784\u5efa\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

### Golang\u6253\u5305exe: \u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecdGolang \u662f\u4e00\u95e8\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4f7f\u7528\u5176\u7f16\u8bd1\u5668\uff08\u5982\uff1ago build\uff09\u5c06\u4ee3\u7801\u7f16\u8bd1\u4e3a\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7136\u540e\u5728\u76ee\u6807\u7cfb\u7edf\u4e0a\u76f4\u63a5\u8fd0\u884c\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9502,9503,24,12,82],"topic":[],"class_list":["post-5050","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-deb","tag-nwvueexe","tag-24","tag-12","tag-82"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/5050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=5050"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/5050\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=5050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=5050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=5050"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=5050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}