【问题标题】:libtiff x64 visual studio 2017 : Linker Issuelibtiff x64 Visual Studio 2017:链接器问题
【发布时间】:2019-06-15 14:27:51
【问题描述】:

我尝试为 libtiff 使用 nuget 包:=> Package <=

为了读取多帧图像 tif 文件,我编写了一小段代码。

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;
}

我需要使用 libtiff,因为我需要用我的图像的 exif 数据做一些 OpenCV 不允许我做的事情。

问题是当我想编译时,我有链接器错误:

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   

我的 package.config 文件是这样的:

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

当我继续我的项目属性时,我看不到任何包参数。 我尝试将手动链接器选项添加到 .lib 文件,但我遇到了同样的问题。

【问题讨论】:

  • inflateInit 看起来像来自 zlib 的符号。手动构建 libtiff 而不是使用该包也是一个好主意
  • 链接器问题可能与链接器设置有关,但也与您尝试编译的内容与您正在链接的库有关,即您的项目是 64 位构建但您要链接的库是32 位,或动态与静态库。所以检查这些很重要。有时我发现在设置中使用绝对路径也有助于解决这些问题。
  • 可以确定的是,我使用的是 x64 软件包,而我的软件也是 x64。只是我不知道如何管理包的配置。你知道我在哪里可以检查路径吗?

标签: c++ visual-studio 64-bit linker-errors libtiff


【解决方案1】:

正如@ReturnVoid 所说,使用 nuget 包下载的库没有为我的系统正确编译。

解决问题:

  • 继续libtiff index 并下载最新版本。
  • 进入下载目录并使用cmake通过以下命令生成它:

    cmake -G "Visual Studio 15 2017 Win64"

  • 完成后,使用 Visual Studio 2017 打开项目

  • 同时构建 Debug 和 Release 库(您可以在 libtiff 子目录中找到它)。

  • 将 \libtiff 添加为包含目录。添加 \libtiff\Release 作为链接器的 目录添加 tiff.lib 作为链接库添加预构建查询以复制 tiff.dll 和 tiffxx.dll 到输出目录。

【讨论】:

    【解决方案2】:
    <?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>
    

    可能是依赖问题。我的 nuget 包配置在上面。

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 2019-07-25
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多