title: how to build leveldb's single test files?
body: <p>i kown it's about gtest framework, i can use gtest for my own demo but in leveldb repo i don't know how to build a single test file such as:leveldb/db/db_test.cc, it will report other confused errors.</p>
  <p>precondition:</p>
  <ul>
  <li>what i want is debug a single testfile such as db_test.cc.</li>
  </ul>
  <p>i use vscode, this is part of my task.json which i think already contains all needed:</p>
  <pre><code>                &quot;args&quot;: [
                  &quot;-fdiagnostics-color=always&quot;,
                  &quot;-g&quot;,
                  &quot;${file}&quot;,
                  &quot;-o&quot;,
                  &quot;${fileDirname}/${fileBasenameNoExtension}&quot;,
                  &quot;-I&quot;, &quot;/root/wzy/code/cpp/leveldb/include&quot;,
                  &quot;-I&quot;, &quot;/root/wzy/code/cpp/leveldb&quot;,
                  &quot;-I&quot;, &quot;/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include&quot;,
                  &quot;-L&quot;, &quot;/root/wzy/code/cpp/leveldb/build&quot;,
                  &quot;-lleveldb&quot;,
                  &quot;-lsnappy&quot;,
                  &quot;-pthread&quot;
              ]
  </code></pre>
  <p>and build errors like these:</p>
  <pre><code>/usr/bin/g++ -fdiagnostics-color=always -g /root/wzy/code/cpp/leveldb/db/db_test.cc -o /root/wzy/code/cpp/leveldb/db/db_test -I /root/wzy/code/cpp/leveldb/include -I /root/wzy/code/cpp/leveldb -I /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include -L /root/wzy/code/cpp/leveldb/build -lleveldb -lsnappy -lpthread
  In file included from /root/wzy/code/cpp/leveldb/db/db_test.cc:12:
  /root/wzy/code/cpp/leveldb/db/db_impl.h:174:3: error: 'port' does not name a type
    174 |   port::Mutex mutex_;
        |   ^~~~
  /root/wzy/code/cpp/leveldb/db/db_impl.h:176:3: error: 'port' does not name a type
    176 |   port::CondVar background_work_finished_signal_ GUARDED_BY(mutex_);
        |   ^~~~
  In file included from /root/wzy/code/cpp/leveldb/db/db_test.cc:14:
  /root/wzy/code/cpp/leveldb/db/version_set.h:181:41: error: 'port' has not been declared
    181 |   Status LogAndApply(VersionEdit* edit, port::Mutex* mu)
        |                                         ^~~~
  /root/wzy/code/cpp/leveldb/db/version_set.h:181:52: error: expected ',' or '...' before '*' token
    181 |   Status LogAndApply(VersionEdit* edit, port::Mutex* mu)
        |                                                    ^
  In file included from /root/wzy/code/cpp/leveldb/db/db_test.cc:24:
  /root/wzy/code/cpp/leveldb/util/mutexlock.h:25:22: error: 'port' has not been declared
     25 |   explicit MutexLock(port::Mutex* mu) EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
        |                      ^~~~
  /root/wzy/code/cpp/leveldb/util/mutexlock.h:25:33: error: expected ')' before '*' token
     25 |   explicit MutexLock(port::Mutex* mu) EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
        |                     ~           ^
        |                                 )
  /root/wzy/code/cpp/leveldb/util/mutexlock.h:34:3: error: 'port' does not name a type
     34 |   port::Mutex* const mu_;
        |   ^~~~
  /root/wzy/code/cpp/leveldb/util/mutexlock.h: In destructor 'leveldb::MutexLock::~MutexLock()':
  /root/wzy/code/cpp/leveldb/util/mutexlock.h:28:42: error: 'class leveldb::MutexLock' has no member named 'mu_'
     28 |   ~MutexLock() UNLOCK_FUNCTION() { this-&gt;mu_-&gt;Unlock(); }
        |                                          ^~~
  In file included from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-spec-builders.h:75,
                   from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-function-mocker.h:42,
                   from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h:61,
                   from /root/wzy/code/cpp/leveldb/util/testutil.h:8,
                   from /root/wzy/code/cpp/leveldb/db/db_test.cc:25:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In member function 'testing::internal::FieldsAreMatcher&lt;Inner&gt;::operator testing::Matcher&lt;T&gt;() const':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:3165:49: error: 'IndexSequenceFor' was not declared in this scope; did you mean 'IndexSequence'?
   3165 |         new FieldsAreMatcherImpl&lt;const Struct&amp;, IndexSequenceFor&lt;Inner...&gt;&gt;(
        |                                                 ^~~~~~~~~~~~~~~~
        |                                                 IndexSequence
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:3165:71: error: expected parameter pack before '...'
   3165 |         new FieldsAreMatcherImpl&lt;const Struct&amp;, IndexSequenceFor&lt;Inner...&gt;&gt;(
        |                                                                       ^~~
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:3165:71: error: template argument 2 is invalid
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4291:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4291 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4291:31: error: expected ',' or '...' before '&lt;' token
   4291 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::StrEqualityMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::StrEq(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4293:61: error: 'str' was not declared in this scope; did you mean 'std'?
   4293 |       internal::StrEqualityMatcher&lt;std::string&gt;(std::string(str), true, true));
        |                                                             ^~~
        |                                                             std
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4299:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4299 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4299:31: error: expected ',' or '...' before '&lt;' token
   4299 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::StrEqualityMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::StrNe(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4301:61: error: 'str' was not declared in this scope; did you mean 'std'?
   4301 |       internal::StrEqualityMatcher&lt;std::string&gt;(std::string(str), false, true));
        |                                                             ^~~
        |                                                             std
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4307:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4307 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4307:31: error: expected ',' or '...' before '&lt;' token
   4307 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::StrEqualityMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::StrCaseEq(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4309:61: error: 'str' was not declared in this scope; did you mean 'std'?
   4309 |       internal::StrEqualityMatcher&lt;std::string&gt;(std::string(str), true, false));
        |                                                             ^~~
        |                                                             std
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4315:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4315 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4315:31: error: expected ',' or '...' before '&lt;' token
   4315 |     const internal::StringLike&lt;T&gt;&amp; str) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::StrEqualityMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::StrCaseNe(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4317:19: error: 'str' was not declared in this scope; did you mean 'std'?
   4317 |       std::string(str), false, false));
        |                   ^~~
        |                   std
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4324:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4324 |     const internal::StringLike&lt;T&gt;&amp; substring) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4324:31: error: expected ',' or '...' before '&lt;' token
   4324 |     const internal::StringLike&lt;T&gt;&amp; substring) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::HasSubstrMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::HasSubstr(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4326:59: error: 'substring' was not declared in this scope; did you mean 'IsSubstring'?
   4326 |       internal::HasSubstrMatcher&lt;std::string&gt;(std::string(substring)));
        |                                                           ^~~~~~~~~
        |                                                           IsSubstring
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4332:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4332 |     const internal::StringLike&lt;T&gt;&amp; prefix) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4332:31: error: expected ',' or '...' before '&lt;' token
   4332 |     const internal::StringLike&lt;T&gt;&amp; prefix) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::StartsWithMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::StartsWith(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4334:60: error: 'prefix' was not declared in this scope; did you mean 'profil'?
   4334 |       internal::StartsWithMatcher&lt;std::string&gt;(std::string(prefix)));
        |                                                            ^~~~~~
        |                                                            profil
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4340:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
   4340 |     const internal::StringLike&lt;T&gt;&amp; suffix) {
        |                     ^~~~~~~~~~
        |                     Strings
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4340:31: error: expected ',' or '...' before '&lt;' token
   4340 |     const internal::StringLike&lt;T&gt;&amp; suffix) {
        |                               ^
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher&lt;testing::internal::EndsWithMatcher&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; testing::EndsWith(int)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4342:58: error: 'suffix' was not declared in this scope
   4342 |       internal::EndsWithMatcher&lt;std::string&gt;(std::string(suffix)));
        |                                                          ^~~~~~
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In member function 'bool testing::internal::ExceptionMatcherImpl&lt;Err&gt;::MatchAndExplain(T&amp;&amp;, testing::MatchResultListener*) const':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:5150:77: error: no matching function for call to 'GetTypeName(const std::type_info&amp;)'
   5150 |       *listener &lt;&lt; &quot;throws an exception of type &quot; &lt;&lt; GetTypeName(typeid(err));
        |                                                                             ^
  In file included from /usr/include/gtest/internal/gtest-internal.h:67,
                   from /usr/include/gtest/gtest.h:62,
                   from /root/wzy/code/cpp/leveldb/db/db_test.cc:11:
  /usr/include/gtest/internal/gtest-type-util.h:80:13: note: candidate: 'template&lt;class T&gt; std::string testing::internal::GetTypeName()'
     80 | std::string GetTypeName() {
        |             ^~~~~~~~~~~
  /usr/include/gtest/internal/gtest-type-util.h:80:13: note:   template argument deduction/substitution failed:
  In file included from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-spec-builders.h:75,
                   from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-function-mocker.h:42,
                   from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h:61,
                   from /root/wzy/code/cpp/leveldb/util/testutil.h:8,
                   from /root/wzy/code/cpp/leveldb/db/db_test.cc:25:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:5150:77: note:   candidate expects 0 arguments, 1 provided
   5150 |       *listener &lt;&lt; &quot;throws an exception of type &quot; &lt;&lt; GetTypeName(typeid(err));
        |                                                                             ^
  In file included from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h:63,
                   from /root/wzy/code/cpp/leveldb/util/testutil.h:8,
                   from /root/wzy/code/cpp/leveldb/db/db_test.cc:25:
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h: In member function 'decltype (testing::internal::InvokeArgument(get&lt;index&gt;(std::forward_as_tuple((forward&lt;Args&gt;)(args)...)), (declval&lt;const Params&amp;&gt;)()...)) testing::internal::InvokeArgumentAction&lt;index, Params&gt;::operator()(Args&amp;&amp; ...) const':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h:519:47: error: 'FlatTupleConstructTag' was not declared in this scope
    519 |     internal::FlatTuple&lt;Args&amp;&amp;...&gt; args_tuple(FlatTupleConstructTag{},
        |                                               ^~~~~~~~~~~~~~~~~~~~~
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h: In function 'testing::internal::InvokeArgumentAction&lt;index, typename std::decay&lt;Params&gt;::type ...&gt; testing::InvokeArgument(Params&amp;&amp; ...)':
  /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h:564:17: error: 'FlatTupleConstructTag' is not a member of 'testing::internal'
    564 |       internal::FlatTupleConstructTag{}, std::forward&lt;Params&gt;(params)...)};
        |                 ^~~~~~~~~~~~~~~~~~~~~
  /root/wzy/code/cpp/leveldb/db/db_test.cc: At global scope:
  /root/wzy/code/cpp/leveldb/db/db_test.cc:61:3: error: 'port' does not name a type
     61 |   port::Mutex mu_;
        |   ^~~~
  /root/wzy/code/cpp/leveldb/db/db_test.cc: In member function 'void leveldb::{anonymous}::AtomicCounter::IncrementBy(int)':
  /root/wzy/code/cpp/leveldb/db/db_test.cc:48:18: error: 'mu_' was not declared in this scope
     48 |     MutexLock l(&amp;mu_);
        |                  ^~~
  /root/wzy/code/cpp/leveldb/db/db_test.cc: In member function 'int leveldb::{anonymous}::AtomicCounter::Read()':
  /root/wzy/code/cpp/leveldb/db/db_test.cc:52:18: error: 'mu_' was not declared in this scope
     52 |     MutexLock l(&amp;mu_);
        |                  ^~~
  /root/wzy/code/cpp/leveldb/db/db_test.cc: In member function 'void leveldb::{anonymous}::AtomicCounter::Reset()':
  /root/wzy/code/cpp/leveldb/db/db_test.cc:56:18: error: 'mu_' was not declared in this scope
     56 |     MutexLock l(&amp;mu_); 
  </code></pre>
  <p>thanks @Tsyvarev, I defined a LEVELDB_PLATFORM_POSIX in source and this &quot;prot&quot; err is missing, but other errs still exist, I will keep doing this till I can GDB a single gtest file.</p>