title: Android Studio .cpp inclusion
body: <p>I'm using a recent build of Android Studio (3.0) and I am starting to use native C++ in my code.</p>
  
  <p>Using the default project settings, everything works as desired; however, I have now added dog.h and dog.cpp to test linking.</p>
  
  <p>dog.h</p>
  
  <pre><code>#ifndef TESTCPLUSPLUSHEADERTEST_DOG_H
  #define TESTCPLUSPLUSHEADERTEST_DOG_H
  
  #include &lt;string&gt;
  
  std::string get_dog();
  
  #endif //TESTCPLUSPLUSHEADERTEST_DOG_H
  </code></pre>
  
  <p>dog.cpp</p>
  
  <pre><code>#include "dog.h"
  
  std::string get_dog() {
      return "dog";
  }
  </code></pre>
  
  <p>native-lib.cpp</p>
  
  <pre><code>#include "dog.h"
  #include &lt;jni.h&gt;
  #include &lt;string&gt;
  
  extern "C"
  JNIEXPORT jstring
  
  JNICALL
  Java_com_test_android_testcplusplusheadertest_MainActivity_getDogString(
          JNIEnv *env,
          jobject /* this */) {
      std::string dog = get_dog();
      ... [other code]
  }
  </code></pre>
  
  <p>CMakeLists.txt</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4.1)
  
  add_library( # Sets the name of the library.
               native-lib
  
               # Sets the library as a shared library.
               SHARED
  
               # Provides a relative path to your source file(s).
               src/main/cpp/native-lib.cpp )
  
  add_library(
           dog
            SHARED
            src/main/cpp/dog.h
            src/main/cpp/dog.cpp
            )
  
  find_library( log-lib
                log )
  
  target_link_libraries( native-lib
                         ${log-lib} )
  
  target_link_libraries( dog
                         ${dog} )
  </code></pre>
  
  <p>When I try to run, I get the following error:</p>
  
  <pre><code>Error:(25) undefined reference to 'get_dog()'
  </code></pre>
  
  <p>This can be fixed by moving the code from dog.cpp into dog.h.</p>
  
  <p>This same class works perfectly well in Visual Studio.</p>
  
  <p>I guess I am doing something wrong with the way I am including the files, but I can't figure out what it is yet.</p>