title: Can't link libtiff
body: <p>I'm trying to build a C++ program using Microsoft Visual Studio 2017.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/imgcodecs.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  extern "C" {
       #include "libtiff/libtiff/tiffio.h"
  }
  
  using namespace cv;
  using namespace std;
  
  int main(int argc, char** argv)
  {
  string imageName("410.tif"); // start with a default
  
                               // If there is an argument, read it in as the name of the image
  if (argc &gt; 1)
  {
      imageName = argv[1];
  }
  
  // Open the TIFF file using libtiff
  TIFF* tif = TIFFOpen(imageName.c_str(), "r");
  
  // Create a matrix to hold the tif image in
  Mat image;
  
  // check the tif is open
  if (tif) {
      do {
          unsigned int width, height;
          uint32* raster;
  
          // get the size of the tiff
          TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &amp;width);
          TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &amp;height);
  
          uint npixels = width * height; // get the total number of pixels
  
          raster = (uint32*)_TIFFmalloc(npixels * sizeof(uint32)); // allocate temp memory (must use the tiff library malloc)
          if (raster == NULL) // check the raster's memory was allocaed
          {
              TIFFClose(tif);
              cerr &lt;&lt; "Could not allocate memory for raster of TIFF image" &lt;&lt; endl;
              return -1;
          }
  
          // Check the tif read to the raster correctly
          if (!TIFFReadRGBAImage(tif, width, height, raster, 0))
          {
              TIFFClose(tif);
              cerr &lt;&lt; "Could not read raster of TIFF image" &lt;&lt; endl;
              return -1;
          }
  
          image = Mat(width, height, CV_8UC4); // create a new matrix of w x h with 8 bits per channel and 4 channels (RGBA)
  
                                               // itterate through all the pixels of the tif
          for (uint x = 0; x &lt; width; x++)
              for (uint y = 0; y &lt; height; y++)
              {
                  uint32&amp; TiffPixel = raster[y*width + x]; // read the current pixel of the TIF
                  Vec4b&amp; pixel = image.at&lt;Vec4b&gt;(Point(y, x)); // read the current pixel of the matrix
                  pixel[0] = TIFFGetB(TiffPixel); // Set the pixel values as BGRA
                  pixel[1] = TIFFGetG(TiffPixel);
                  pixel[2] = TIFFGetR(TiffPixel);
                  pixel[3] = TIFFGetA(TiffPixel);
              }
  
          _TIFFfree(raster); // release temp memory
                             // Rotate the image 90 degrees couter clockwise
          image = image.t();
          flip(image, image, 0);
          imshow("TIF Image", image); // show the image
          waitKey(0); // wait for anykey before displaying next
      } while (TIFFReadDirectory(tif)); // get the next tif
      TIFFClose(tif); // close the tif file
  }
      return 0;
  }
  </code></pre>
  
  <p>As you can see, I include libtiff but when I try to compile I get the following error:</p>
  
  <blockquote>
    <p>LNK2019   reference to the external symbol _TIFFmalloc not resolved in
    the function</p>
  </blockquote>
  
  <p>The error is extended to "_TIFFfree,TIFFClose, TIFFGetField, TIFFReadDirectory, TIFFReadRGBAImage, TIFFOpen" (I posted only one to be easier).</p>
  
  <p>I tried to search on google about this problem and I think that this is caused by a linking problem. A lot of people told that I should add "libtiff.lib" in the "input" section of Visual Studio project's properties but I have no libtiff.lib in the library I downloaded from the official source.</p>
  
  <p>I'm using the 4.0.4 version of the library.</p>