title: GTest not finding tests in separate compilation units
body: <p>I've got a program written in C++, with some subfolders containing libraries linked in. There's a top level SConscript, which calls SConscript files in the subfolders/libraries.</p>
  <p>Inside a library cpp, there is a GTest test function:</p>
  <pre><code>TEST(X, just_a_passing_test) {
  EXPECT_EQ(true, true);
  }
  </code></pre>
  <p>There is <code>main()</code> in the top level program source, which just calls GTests main, and has another GTest test within it:</p>
  <pre><code>int main(int argc, char** argv) {
  ::testing::InitGoogleTest(&amp;argc, argv);
  return RUN_ALL_TESTS();
  }
  
  TEST(Dummy, should_pass){
  EXPECT_EQ(true, true);
  }
  </code></pre>
  <p>Now the issue is that when I run the program, GTest only runs the test in the <code>main.cpp</code> source. Ignoring the test in the library. Now it gets bizarre when I reference an unrelated class in the same library cpp in <code>main.cpp</code>, in a no side-effect kind of way (eg. <code>SomeClass foo;</code>), the test magically appears. I've tried using -O0 and other tricks to force gcc to not optimize out code that isn't called. I've even tried Clang.
  I suspect it's something to do with how GTest does test discovery during compilation, but I can't find any info on this issue. I believe it uses static initialization, so maybe there's some weird ordering going on there.
  Any help/info is greatly appreciated!</p>
  <p><strong>Update:</strong> Found a section in the FAQ that sounds like this problem, despite it referring specifically to Visual C++. Which includes a trick/hack to force the compiler to not discard the library if not referenced.
  It recommends not putting tests in libraries, but that leaves me wondering how else would you test libraries, without having an executable for every one, making quickly running them a pain and with bloated output.
  <a href="https://code.google.com/p/googletest/wiki/Primer#Important_note_for_Visual_C++_users" rel="nofollow noreferrer">https://code.google.com/p/googletest/wiki/Primer#Important_note_for_Visual_C++_users</a></p>