title: Cant compile googletest on OSX Yosemite
body: <p>I have read a few related answers and some articles online as well as the official Google Test documentation, but since I lack experience in this area I am very insecure about a few things and seek guidance.</p>
  
  <p>I am starting a brand new pet project in c++ and I want to write proper tests as I code along, ran into Google Test and decided to give it a try. </p>
  
  <p>Currently this is my folder structure:</p>
  
  <pre><code>/
  /bin
  /main.cpp
  /lib
  /lib/db
  /lib/external/googletest
  </code></pre>
  
  <p>My idea is to have the tests and class files in their own folders, for example:</p>
  
  <pre><code>/lib/db/db.h
  /lib/db/db.cpp
  /lib/db/db.test
  </code></pre>
  
  <h1>Question #1</h1>
  
  <p>Is there a naming convention or expectation for the file containing the tests? (<code>/lib/db/db.test</code> in that example above)</p>
  
  <h1>Question #2</h1>
  
  <p>I ran the following commands</p>
  
  <ol>
  <li>cd lib/external/googletest/googletest</li>
  <li>cmake .</li>
  <li>make</li>
  <li>make install</li>
  <li>cp lib*.a /usr/local/lib</li>
  <li>cp -r include/gtest/ /usr/local/include/</li>
  </ol>
  
  <p>And seeing how it ended up creating a series of .h files in /usr/local/include/gtest, I expected to be able to <code>#include &lt;gtest/gtest.h&gt;</code> and be able to run tests, I added this to my main.cpp:</p>
  
  <pre><code>TEST(Param1, Param2) {
      EXPECT_EQ(1, 1);
  }
  </code></pre>
  
  <p>and when building the following error showed up:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "testing::AssertionSuccess()", referenced from:
        testing::AssertionResult testing::internal::CmpHelperEQ&lt;int, int&gt;(char const*, char const*, int const&amp;, int const&amp;) in main-230b96.o
    "testing::Test::SetUp()", referenced from:
        vtable for Param1_Param2_Test in main-230b96.o
    "testing::Test::TearDown()", referenced from:
        vtable for Param1_Param2_Test in main-230b96.o
    "testing::Test::Test()", referenced from:
        Param1_Param2_Test::Param1_Param2_Test() in main-230b96.o
    "testing::Test::~Test()", referenced from:
        Param1_Param2_Test::~Param1_Param2_Test() in main-230b96.o
    "testing::Message::Message()", referenced from:
        Param1_Param2_Test::TestBody() in main-230b96.o
    "testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
        Param1_Param2_Test::TestBody() in main-230b96.o
    "testing::internal::AssertHelper::~AssertHelper()", referenced from:
        Param1_Param2_Test::TestBody() in main-230b96.o
    "testing::internal::GetTestTypeId()", referenced from:
        ___cxx_global_var_init in main-230b96.o
    "testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
        ___cxx_global_var_init in main-230b96.o
    "testing::internal::IsTrue(bool)", referenced from:
        testing::internal::scoped_ptr&lt;std::__1::basic_stringstream&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;::reset(std::__1::basic_stringstream&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;*) in main-230b96.o
        testing::internal::scoped_ptr&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;::reset(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;*) in main-230b96.o
    "testing::internal::EqFailure(char const*, char const*, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, bool)", referenced from:
        testing::AssertionResult testing::internal::CmpHelperEQFailure&lt;int, int&gt;(char const*, char const*, int const&amp;, int const&amp;) in main-230b96.o
    "testing::internal::AssertHelper::operator=(testing::Message const&amp;) const", referenced from:
        Param1_Param2_Test::TestBody() in main-230b96.o
    "typeinfo for testing::Test", referenced from:
        typeinfo for Param1_Param2_Test in main-230b96.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: *** [all] Error 1
  </code></pre>
  
  <h1>Solution</h1>
  
  <p>Thanks to trojanfoe I fixed my makefile to look like this:</p>
  
  <pre><code>CC=g++
  target_folder=bin
  all:
      $(CC) *.cpp -o $(target_folder)/prod
      ./bin/prod
  test:
      $(CC) *.cpp -o $(target_folder)/test lib/external/googletest/googletest/libgtest.a lib/external/googletest/googletest/libgtest_main.a
      ./bin/test
  clean:
      rm -f $(target_folder)/* *.o
  </code></pre>
  
  <p>And now it works just fine, please keep in mind that this is a skeleton project and I need to structure the test files and entry point, so at this point its just compiling a basic test.</p>