title: ./libmylib.so: undefined reference to `submarinex::LIB::kCount'
body: <p>I have 3 files in a directory. I will build <code>ll.cc</code> to <code>libmylib.so</code>, and build <code>main.cc</code> to <code>myexe</code>.</p>
  
  <p>Use these command to build</p>
  
  <pre><code>g++ -Wall -g -fPIC -std=c++11 ll.cc -shared -o libmylib.so
  g++ -Wall -g -std=c++11 main.cc -L. -lmylib -o myexe
  </code></pre>
  
  <p>But, g++ report a error when build <code>myexe</code> :</p>
  
  <pre><code>./libmylib.so: undefined reference to `submarinex::LIB::kCount'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>Files:</p>
  
  <p>ll.h</p>
  
  <pre><code>namespace submarinex {
  
  class LIB {
   public:
    void Print();
  
   private:
    static const int kCount = 100;
  };
  
  }  // namespace submarinex
  </code></pre>
  
  <p>ll.cc</p>
  
  <pre><code>#include "ll.h"
  
  #include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  
  namespace submarinex {
  
  void LIB::Print() {
    int min = std::min(101, kCount);
    std::cout &lt;&lt; min &lt;&lt; std::endl;
  
    // std::cout &lt;&lt; kCount &lt;&lt; std::endl;
  }
  
  }  // namespace submarinex
  </code></pre>
  
  <p>main.cc</p>
  
  <pre><code>#include "ll.h"
  
  int main(int argc, char **argv) {
    submarinex::LIB lib;
    lib.Print();
  
    return 0;
  }
  </code></pre>
  
  <p><code>Case 1</code>:
  If use these 2 lines in <code>Print</code>, will report an error when link object of main.cc</p>
  
  <pre><code>  int min = std::min(101, kCount);
    std::cout &lt;&lt; min &lt;&lt; std::endl;
  </code></pre>
  
  <p><code>Case 2</code>:
  If use this line in <code>Print</code>, will success</p>
  
  <pre><code>  std::cout &lt;&lt; kCount &lt;&lt; std::endl;
  </code></pre>
  
  <p>If change </p>
  
  <pre><code> static const int kCount = 100;
  </code></pre>
  
  <p>to</p>
  
  <pre><code> const int kCount = 100;
  </code></pre>
  
  <p>it also be OK regardless of using <code>Case1</code> or <code>Case2</code>.</p>
  
  <p>I don't know how to solve this problem.</p>