title: Undefined symbols for architecture x86_64 when writing unit tests with gtest and clang 12
body: <p>I'm trying to add unit tests for some functions defined in this file:</p>
  <ul>
  <li><a href="https://github.com/azerothcore/azerothcore-wotlk/blob/master/src/server/game/Miscellaneous/Formulas.h" rel="nofollow noreferrer">src/server/game/Miscellaneous/Formulas.h</a></li>
  </ul>
  <p>My test file looks like this:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &quot;gtest/gtest.h&quot;
  #include &quot;Formulas.h&quot;
  #include &quot;SharedDefines.h&quot;
  
  using namespace acore::Honor;
  using namespace acore::XP;
  
  TEST(FormulasTest, hk_honor_at_level)
  {
      EXPECT_EQ(hk_honor_at_level(80), 124);
      // some more checks here...
  }
  
  TEST(FormulasTest, GetGrayLevel)
  {
      EXPECT_EQ(GetGrayLevel(0), 0);
      // some more checks here...
  }
  
  TEST(FormulasTest, GetColorCode)
  {
      EXPECT_EQ(GetColorCode(60, 80), XP_RED);
      // some more checks here...
  }
  
  TEST(FormulasTest, GetZeroDifference)
  {
      EXPECT_EQ(GetZeroDifference(1), 5);
      // some more checks here...
  }
  
  TEST(FormulasTest, BaseGain)
  {
      // PROBLEM HERE
      EXPECT_EQ(BaseGain(60, 1, CONTENT_1_60), 0);
  }
  </code></pre>
  <p>the problem arises as soon as I call the function <code>BaseGain</code> defined inside <a href="https://github.com/azerothcore/azerothcore-wotlk/blob/master/src/server/game/Miscellaneous/Formulas.h" rel="nofollow noreferrer">Formulas.h</a>:</p>
  <pre><code>Undefined symbols for architecture x86_64:
    &quot;_LoginDatabase&quot;, referenced from:
        Log::outDB(LogTypes, char const*) in libcommon.a(Log.cpp.o)
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make[3]: *** [src/test/unit_tests] Error 1
  make[2]: *** [src/test/CMakeFiles/unit_tests.dir/all] Error 2
  make[1]: *** [src/test/CMakeFiles/unit_tests.dir/rule] Error 2
  make: *** [unit_tests] Error 2
  </code></pre>
  <p>In particular, the problem is gone if I remove the call to <code>sLog-&gt;outError</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code> sLog-&gt;outError(&quot;BaseGain: Unsupported content level %u&quot;, content);
  </code></pre>
  <p>from <code>BaseGain</code>.</p>
  <p>However, this issue happens only in the unit tests, the rest of the project source code compiles just fine.</p>
  <p>To compile the project including unit tests, pass the <code>-DBUILD_TESTING=1</code> parameter to the <code>cmake</code> command.</p>
  <p><strong>EDIT</strong>: I've already tried adding <code>common</code> to the <code>target_link_libraries</code> of <code>src/test/CMakeLists.txt</code> but this hasn't solved the issue for me.</p>