<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Programming on Mini Fish</title>
    <link>https://blog.minifish.org/tags/programming/</link>
    <description>Recent content in Programming on Mini Fish</description>
    <image>
      <title>Mini Fish</title>
      <url>https://blog.minifish.org/android-chrome-512x512.png</url>
      <link>https://blog.minifish.org/android-chrome-512x512.png</link>
    </image>
    <generator>Hugo -- 0.154.5</generator>
    <language>en-US</language>
    <copyright>Mini Fish 2014-present. Licensed under CC-BY-NC</copyright>
    <lastBuildDate>Thu, 28 Nov 2024 15:41:19 +0800</lastBuildDate>
    <atom:link href="https://blog.minifish.org/tags/programming/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>The Correct Way to Use `go build`</title>
      <link>https://blog.minifish.org/posts/the-correct-way-to-use-go-build/</link>
      <pubDate>Thu, 28 Nov 2024 15:41:19 +0800</pubDate>
      <guid>https://blog.minifish.org/posts/the-correct-way-to-use-go-build/</guid>
      <description>&lt;p&gt;When working with Go, it&amp;rsquo;s important to know the proper way to compile your programs to avoid common errors. Here are some tips on using the &lt;code&gt;go build&lt;/code&gt; command effectively.&lt;/p&gt;
&lt;h2 id=&#34;recommended-usage&#34;&gt;Recommended Usage&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Compile all Go files in the current directory:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;go build
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Compile all Go files explicitly:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;go build *.go
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;common-pitfalls&#34;&gt;Common Pitfalls&lt;/h2&gt;
&lt;h3 id=&#34;compiling-a-single-file&#34;&gt;Compiling a Single File&lt;/h3&gt;
&lt;p&gt;Running:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;go build main.go
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;will only build &lt;code&gt;main.go&lt;/code&gt;. This can lead to errors if &lt;code&gt;main.go&lt;/code&gt; depends on other Go files in the same package, as those files won&amp;rsquo;t be included in the build process.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>When working with Go, it&rsquo;s important to know the proper way to compile your programs to avoid common errors. Here are some tips on using the <code>go build</code> command effectively.</p>
<h2 id="recommended-usage">Recommended Usage</h2>
<ul>
<li>
<p><strong>Compile all Go files in the current directory:</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>go build
</span></span></code></pre></div></li>
<li>
<p><strong>Compile all Go files explicitly:</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>go build *.go
</span></span></code></pre></div></li>
</ul>
<h2 id="common-pitfalls">Common Pitfalls</h2>
<h3 id="compiling-a-single-file">Compiling a Single File</h3>
<p>Running:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>go build main.go
</span></span></code></pre></div><p>will only build <code>main.go</code>. This can lead to errors if <code>main.go</code> depends on other Go files in the same package, as those files won&rsquo;t be included in the build process.</p>
<h3 id="including-non-go-files">Including Non-Go Files</h3>
<p>Using:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>go build *
</span></span></code></pre></div><p>will cause an error if the <code>*</code> wildcard includes non-Go files. The compiler will output an error message stating that only Go files can be compiled. This serves as a precise reminder to exclude non-Go files from the build command.</p>
<hr>
<p>By using <code>go build</code> correctly, you can ensure that all necessary files in your package are compiled together, avoiding missing dependencies and other common compilation issues.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
