Why a simple Hello World program generates a 2.37mb binary?

agolangf · · 510 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>For example, the following code generate a 2.37mb file.</p> <pre><code>package main import ( &#34;fmt&#34; ) func main() { fmt.Println(&#34;Hello World&#34;) } </code></pre> <hr/>**评论:**<br/><br/>lstokeworth: <pre><p>FAQ: <a href="https://golang.org/doc/faq#Why_is_my_trivial_program_such_a_large_binary" rel="nofollow">Why is my trivial program such a large binary?</a></p></pre>: <pre><p>[deleted]</p></pre>skarlso: <pre><p>To the top with this comment.</p></pre>lstokeworth: <pre><p>What did the deleted comment say?</p></pre>skarlso: <pre><p>Basically, RTFM. :-) it is such a simple question that typing it in and submitting took more time than typing it in to Google which would have yielded an answer immediately. </p></pre>scharty: <pre><p>If it&#39;s any consolation, it doesn&#39;t grow super fast. If you get it to print hello world twice, or won&#39;t be 4.6 megs.</p></pre>babawere: <pre><p>It&#39;s been improved at the moment see <a href="https://github.com/golang/go/issues/6853" rel="nofollow"> all: binaries too big and growing #6853</a></p></pre>tu_1t_le: <pre><p>try this : </p> <pre><code>package main func main() { print(&#34;Hello World&#34;) } </code></pre></pre>dchapes: <pre><p>It&#39;s a <em>really</em> bad idea to recommend the built-in <a href="https://golang.org/pkg/builtin/#print" rel="nofollow">print</a> function(s) to Go newcomers (and you meant <code>println</code> anyway). More importantly, it doesn&#39;t address the real reason behind the OP&#39;s FAQ (omitting <code>fmt</code> only saves ~1 MB, and understanding why is part of the question).</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

510 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传