FrsECM
FrsECM

Reputation: 245

libtiff x64 visual studio 2017 : Linker Issue

I tried to use nuget package for libtiff : => Package <=

I wrote a little piece of code in order to read a multiframe image tif file.

vector<Mat> LibTiffReader::ReadMultiframeTiff(std::string FilePath)
{
    vector<Mat> Result;
    TIFF* tif = TIFFOpen(FilePath.c_str(), "r");
    if (tif)
    {
        //Si le tif est ouvert, on itère sur ce qu'il y'a dedans...
        do
        {
            Mat Image;
            unsigned int width, height;
            uint32* raster;

            // On récupère la taille du tiff..
            TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
            TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &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 << "Could not allocate memory for raster of TIFF image" << endl;
                return vector<Mat>();
            }

            if (!TIFFReadRGBAImage(tif, width, height, raster, 0))
            {
                TIFFClose(tif);
                cerr << "Could not read raster of TIFF image" << endl;
                return vector<Mat>();
            }
            Image = Mat(width, height, CV_8UC3); // create a new matrix of w x h with 8 bits per channel and 3 channels (RGBA)

                                                 // itterate through all the pixels of the tif
            for (uint x = 0; x < width; x++)
                for (uint y = 0; y < height; y++)
                {
                    uint32& TiffPixel = raster[y*width + x]; // read the current pixel of the TIF
                    Vec3b& pixel = Image.at<Vec3b>(Point(y, x)); // read the current pixel of the matrix
                    pixel[0] = TIFFGetB(TiffPixel); // Set the pixel values as BGR
                    pixel[1] = TIFFGetG(TiffPixel);
                    pixel[2] = TIFFGetR(TiffPixel);
                }
            _TIFFfree(raster);
            Result.push_back(Image);
        } while (TIFFReadDirectory(tif));
    }

    return Result;
}

I need to use libtiff, because i need to do some stuff with exif data of my image what OpenCV don't allow me to do.

The problem is that when i want to compile, i have linker errors :

Error   LNK2001 unresolved external symbol inflateInit_ SIA <Path>\tiff.lib(tif_zip.obj)    1   
Error   LNK2001 LNK2001 unresolved external symbol inflateInit_ SIA <Path>\tiff.lib(tif_pixarlog.obj)   1   

My package.config file is like that :

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="libtiff-msvc-x64" version="4.0.7.8808" targetFramework="native" />
</packages>

When i go on my project properties, i don't see any packages parameters. I tried to add manualy linker options to .lib files, but i have the same issues.

Upvotes: 0

Views: 3014

Answers (2)

Denny
Denny

Reputation: 177

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="libjpeg" version="9.0.1.4" targetFramework="native" />
  <package id="libjpeg.redist" version="9.0.1.4" targetFramework="native" />
  <package id="libtiff" version="4.0.6.2" targetFramework="native" />
  <package id="libtiff.redist" version="4.0.6.2" targetFramework="native" />
  <package id="libtiff-msvc14-x64" version="4.0.7.7799" targetFramework="native" />
  <package id="zlib" version="1.2.8.8" targetFramework="native" />
  <package id="zlib.v120.windesktop.msvcstl.dyn.rt-dyn" version="1.2.8.8" targetFramework="native" />
  <package id="zlib.v140.windesktop.msvcstl.dyn.rt-dyn" version="1.2.8.8" targetFramework="native" />
</packages>

Maybe dependency problems. My nuget packages config is above.

Upvotes: 0

FrsECM
FrsECM

Reputation: 245

Exactly like said @ReturnVoid, the library downloaded with the nuget package was not compiled correctly for my system.

To solve the problem :

  • Go on libtiff index and download the last version.
  • Go in the download directory and use cmake to generate it with following command :

    cmake -G "Visual Studio 15 2017 Win64"

  • Once it is done, open the project with Visual studio 2017

  • Build both Debug and Release library (you can find it then in libtiff subdirectory).

  • Add \libtiff as include directory. Add \libtiff\Release as Linker's directory Add tiff.lib as Linked library Add a prebuild query to copy tiff.dll and tiffxx.dll to output directory.

Upvotes: 3

Related Questions