{"id":208089,"date":"2025-07-08T10:12:20","date_gmt":"2025-07-08T02:12:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208089\/"},"modified":"2025-07-08T10:12:20","modified_gmt":"2025-07-08T02:12:20","slug":"%e6%9c%89%e4%ba%ba%e5%8f%af%e4%bb%a5%e5%bb%ba%e8%ae%ae%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bb%8e%e6%ba%90%e4%bb%a3%e7%a0%81%ef%bc%881-4%ef%bc%89%e5%bc%80%e5%a7%8b%e6%9e%84%e5%bb%ba%e4%bc%9a%e5%9b%a0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208089\/","title":{"rendered":"\u6709\u4eba\u53ef\u4ee5\u5efa\u8bae\u4e3a\u4ec0\u4e48\u4ece\u6e90\u4ee3\u7801\uff081.4\uff09\u5f00\u59cb\u6784\u5efa\u4f1a\u56e0\u4e3a GCC \u7f16\u8bd1\u9519\u8bef\u800c\u5931\u8d25\uff0c\u5373\u4f7f CGO_ENABLED=0"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u6709\u4eba\u53ef\u4ee5\u5efa\u8bae\u4e3a\u4ec0\u4e48\u4ece\u6e90\u4ee3\u7801\uff081.4\uff09\u5f00\u59cb\u6784\u5efa\u4f1a\u56e0\u4e3a GCC \u7f16\u8bd1\u9519\u8bef\u800c\u5931\u8d25\uff0c\u5373\u4f7f CGO_ENABLED=0<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-28 21:09:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u6709\u4eba\u53ef\u4ee5\u5efa\u8bae\u4e3a\u4ec0\u4e48\u4ece\u6e90\u4ee3\u7801\uff081.4\uff09\u5f00\u59cb\u6784\u5efa\u4f1a\u56e0\u4e3a GCC \u7f16\u8bd1\u9519\u8bef\u800c\u5931\u8d25\uff0c\u5373\u4f7f CGO_ENABLED=0\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5728 go\/src \u4e2d\u627e\u5230\u7684\u6587\u4ef6 make.bat\uff08\u89e3\u538b tar \u540e\uff09\u4e2d\uff0c\u751a\u81f3\u5728\u4f7f\u7528 cgo_enabled \u68c0\u67e5\u4e4b\u524d\u5c31\u6709\u4e00\u4e2a gcc \u7f16\u8bd1\u547d\u4ee4\u3002\u8fd9\u4f1a\u6270\u4e71\u5f15\u5bfc\u5de5\u5177\u7684\u6784\u5efa\u3002<\/p>\n<p>\u51fa\u4e8e\u5b89\u5168\u539f\u56e0\uff0c\u6211\u65e0\u6cd5\u901a\u8fc7 cygwin \u6216 ming \u5728 windows \u4e0a\u5b89\u88c5 gcc\u3002\u7136\u800c\uff0c\u7f16\u8bd1\u662f\u9488\u5bf9\u5404\u79cd .c \u6587\u4ef6\u7684\uff0c\u8fd9\u8ba9\u6211\u4e0d\u786e\u5b9a\u4e0b\u4e00\u6b65\u8be5\u505a\u4ec0\u4e48\u3002<\/p>\n<p>\u6211\u5df2\u7ecf\u4fee\u6539\u4e86\u6e90\u4ee3\u7801\u548c\u73af\u5883\u53d8\u91cf\uff0c\u7279\u522b\u662f cgo_enabled\uff0c\u8fd9\u5e94\u8be5\u662f\u6211\u6240\u9700\u8981\u7684\u3002\u7136\u800c\uff0cmake.bat \u5177\u6709\u4ee4\u4eba\u607c\u706b\u7684\u5c0f c \u7f16\u8bd1\uff0c\u8fd9\u4f3c\u4e4e\u8ba9\u6211\u611f\u5230\u538c\u70e6\u3002<\/p>\n<p>\u8fd9\u662f make.bat \u6587\u4ef6\u548c\u8ba9\u6211\u5931\u671b\u7684\u7f16\u8bd1\uff1a<\/p>\n<pre>:: CGO_ENABLED: Controls cgo usage during the build. Set it to 1\n:: to include all cgo related files, .c and .go file with \"cgo\"\n:: build directive, in the build. Set it to 0 to ignore them.\n\n@echo off\n\n:: Keep environment variables within this script\n:: unless invoked with --no-local.\nif x%1==x--no-local goto nolocal\nif x%2==x--no-local goto nolocal\nsetlocal\n:nolocal\n\nset GOBUILDFAIL=0\n\nif exist make.bat goto ok\necho Must run make.bat from Go src directory.\ngoto fail \n:ok\n\n:: Clean old generated file that will cause problems in the build.\ndel \/F \".\\pkg\\runtime\\runtime_defs.go\" 2&gt;NUL\n\n:: Grab default GOROOT_FINAL and set GOROOT for build.\n:: The expression %VAR:\\=\\\\% means to take %VAR%\n:: and apply the substitution \\ = \\\\, escaping the\n:: backslashes.  Then we wrap that in quotes to create\n:: a C string.\ncd ..\nset GOROOT=%CD%\ncd src\nif \"x%GOROOT_FINAL%\"==\"x\" set GOROOT_FINAL=%GOROOT%\nset DEFGOROOT=-DGOROOT_FINAL=\"\\\"%GOROOT_FINAL:\\=\\\\%\\\"\"\n\necho # Building C bootstrap tool.\necho cmd\/dist\/*.c\nif not exist ..\\bin\\tool mkdir ..\\bin\\tool\n:: Windows has no glob expansion, so spell out cmd\/dist\/*.c.\ngcc -O2 -Wall -Werror -o cmd\/dist\/dist.exe -Icmd\/dist %DEFGOROOT% cmd\/dist\/buf.c cmd\/dist\/build.c cmd\/dist\/buildgc.c cmd\/dist\/buildgo.c cmd\/dist\/buildruntime.c cmd\/dist\/main.c cmd\/dist\/windows.c cmd\/dist\/arm.c\nif errorlevel 1 goto fail\n.\\cmd\\dist\\dist env -wp &gt;env.bat\nif errorlevel 1 goto fail\ncall env.bat\ndel env.bat\necho.<\/pre>\n<p>\u6700\u7ec8\u7ed3\u679c\u53ea\u662f\u4e00\u4e2a\u6807\u51c6\u7684 gcc \u9519\u8bef\uff1a<\/p>\n<p>\u6784\u5efa c \u5f15\u5bfc\u5de5\u5177\u3002<\/p>\n<p>cmd\/dist\/*.c<\/p>\n<p>\u201cgcc\u201d\u4e0d\u88ab\u8bc6\u522b\u4e3a&#8230;<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>Go 1.4 \u662f\u7528 C \u7f16\u5199\u7684\uff0c\u56e0\u6b64\u9700\u8981 C \u6765\u7f16\u8bd1\u3002 CGO\u4e0e\u6b64\u5b8c\u5168\u65e0\u5173\u3002<\/p>\n<p> \u662f\u7b2c\u4e00\u4e2a\u4e0d\u9700\u8981 C \u6784\u5efa\u7684\u7248\u672c\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u6709\u4eba\u53ef\u4ee5\u5efa\u8bae\u4e3a\u4ec0\u4e48\u4ece\u6e90\u4ee3\u7801\uff081.4\uff09\u5f00\u59cb\u6784\u5efa\u4f1a\u56e0\u4e3a GCC \u7f16\u8bd1\u9519\u8bef\u800c\u5931\u8d25\uff0c\u5373\u4f7f CGO_ENABLED=0\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-208089","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208089"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208089\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}