Link libjpeg-turbo in vs c++ 2017

自闭症网瘾萝莉.ら 提交于 2020-01-13 07:12:22

问题


my problem is fairly simple.. I'm not able to link libjpeg-turbo in my project.

I'm looking to try this exemple, but i'm not able to compile :

I'm not sure what i'm doing wrong :


回答1:


You can download vcpkg from github and run vcpkg.exe in the Powershell prompt( opened in administrative mode) . vcpkg can install many open source projects (both static and dynamic libraries are supported) as packages ready for use in VS 2017 and VS 2015 (SP3) IDE. You can use choose x86 or x64 platform and in some cases even allows selection of toolset ( eg .\vcpkg install boost:x64-windows-v141 ). If you use 'integrate install' as the vcpkg command line, all the libraries will be automatically linked with your project and the project .dll files will be automatically copied to your application folder.

So, in your case, after the the installation of vcpkg.exe, you type .\vcpkg install libjpeg-turbo:x64-windows-static and after installation type .\vcpkg integrate install. The jpeg library will be linked automatically to your project (Restart your VS 2017 and enjoy).




回答2:


Note that for turbojpeg-static.lib you cannot compile with >VS2010 unless you recompile libjpegturbo yourself...

I recommend using MinGW for building if you can; it is possible to use the turbojpeg static library without issues.

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.


来源:https://stackoverflow.com/questions/48740107/link-libjpeg-turbo-in-vs-c-2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!