title: Including C File/Linking with CMake isn't working with C++: cannot include function
body: <p>This is my C++ code:</p>
  
  <pre><code>#include "stdlib.h"
  #include "stdio.h"
  #include &lt;iostream&gt;
  
  
  int main(int argc, char *argv[] ) {     
      int width, height;
      unsigned char *rgba;
      FILE *fp = fopen("/home/pic.tif", "rb");
      if(!fp)
          std::cout&lt;&lt;"failed"&lt;&lt;std::endl;
      rgba = floadtiff(fp, &amp;width, &amp;height);
      fclose(fp);
  
      if(rgba == 0)
          printf("TIFF file unreadable\n");
  }
  </code></pre>
  
  <p>I am using <a href="https://github.com/MalcolmMcLean/tiffloader" rel="nofollow noreferrer">this</a> library by @MalcolmMcLean, and that's what my loadtiff.c is.I have compiled it using gcc and am trying to link that library.</p>
  
  <p>This is my CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.12.2)
  project (test)
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} cmake/)
  add_executable(test tiffs.cpp)
  target_link_libraries(test loadtiff)
  </code></pre>
  
  <p>and these are the errors I get when trying to make the program:</p>
  
  <pre><code>error: ‘floadtiff’ was not declared in this scope
  </code></pre>
  
  <p>Why can't I access this function, which is defined in loadtiff.c?</p>