Link vs c++ 2017 中的 libjpeg-turbo

Link libjpeg-turbo in vs c++ 2017

我的问题很简单。我无法在我的项目中 link libjpeg-turbo。

我想尝试 this exemple,但我无法编译 :

我不确定我做错了什么:

您可以在 Powershell 提示符下(以管理模式打开)从 github 和 运行 vcpkg.exe 下载 vcpkg。 vcpkg 可以安装许多开源项目(支持静态库和动态库)作为准备在 VS 2017 和 VS 2015 (SP3) 中使用的包 IDE。您可以使用选择 x86 或 x64 平台,在某些情况下甚至允许选择工具集(例如 .\vcpkg install boost:x64-windows-v141 )。如果您使用 'integrate install' 作为 vcpkg 命令行,所有库将自动链接到您的项目,并且项目的 .dll 文件将自动复制到您的应用程序文件夹。

因此,在您的情况下,在安装 vcpkg.exe 之后,您键入 .\vcpkg install libjpeg-turbo:x64-windows-static 并在安装后键入 .\vcpkg integrate install . jpeg 库将自动链接到您的项目(重新启动您的 VS 2017 并享受)。

请注意,对于 turbojpeg-static.lib,您无法使用 >VS2010 进行编译,除非您自己重新编译 libjpegturbo...

如果可以,我建议使用 MinGW 进行构建;可以毫无问题地使用 turbojpeg 静态库。

https://github.com/libjpeg-turbo/libjpeg-turbo/issues/45#issuecomment-181690889

RE: the first issue, you can get rid of the unresolved _snprintf_s symbol error by linking with legacy_stdio_definitions.lib. However, the second error ("unresolved external symbol __iob_func") is not easily solvable. It's due to the new "universal C runtime" (ucrt) library that Microsoft introduced recently. Unfortunately that new library introduces some pretty major incompatibilities with previous Microsoft CRT's.

Referring to http://www.libjpeg-turbo.org/Documentation/OfficialBinaries, it has never been possible to fully isolate the CRT in libjpeg-turbo, because two of the libjpeg API functions (jpeg_stdio_dest() and jpeg_stdio_src()) require passing a FILE handle from the calling program to the library. If the libjpeg API library is being used as a DLL (jpeg62.dll), then the calling program must share the same CRT DLL as jpeg62.dll, or else passing a FILE handle from one to the other wouldn't work (the FILE pointer would point to an opaque structure in either the memory space of the application or the DLL, so the pointer would be meaningless to the other.)

Traditionally, it was possible to link with the static libjpeg-turbo libraries, even when using a different version of Visual C++ than the one used to compile the libraries, but apparently that has never been supported (https://connect.microsoft.com/VisualStudio/feedback/details/1144980/error-lnk2001-unresolved-external-symbol-imp-iob-func) and worked only because the CRT's in different versions of Visual C++ were reasonably similar. Apparently all of that went out the window with the introduction of the ucrt. Googling the error message reveals that we're far from the only OSS project suffering from this.

At the moment, these are the only workarounds I know of:

  • If you're using the TurboJPEG API, you can link against turbojpeg.dll instead of turbojpeg-static.lib.
  • If you're using the libjpeg API, you can link against jpeg62.dll instead of jpeg-static.lib, provided that your application isn't calling jpeg_stdio_src() or jpeg_stdio_dest().
  • If you need to use jpeg-static.lib or turbojpeg-static.lib, you'll need to either build your application with an older version of Visual C++ or build libjpeg-turbo using Visual C++ 2015.