简体   繁体   English

在vs C ++ 2017中链接libjpeg-turbo

[英]Link libjpeg-turbo in vs c++ 2017

my problem is fairly simple.. I'm not able to link libjpeg-turbo in my project. 我的问题很简单..我无法在项目中链接libjpeg-turbo。

I'm looking to try this exemple , but i'm not able to compile : 我正在尝试尝试这个示例 ,但是我无法编译:

错误

I'm not sure what i'm doing wrong : 我不确定我在做什么错:

附加lib目录 附加部

其他包括

You can download vcpkg from github and run vcpkg.exe in the Powershell prompt( opened in administrative mode) . 您可以从github下载vcpkg并在Powershell提示符(以管理模式打开)中运行vcpkg.exe。 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. vcpkg可以将许多开源项目(支持静态和动态库)安装为可在VS 2017和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 ). 您可以使用x86或x64平台,在某些情况下甚至可以选择工具集(例如。\\ 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. 如果您使用“集成安装”作为vcpkg命令行,则所有库将自动与您的项目链接,并且项目.dll文件将自动复制到您的应用程序文件夹。

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. 因此,就您而言,在安装vcpkg.exe之后,您键入。\\ vcpkg安装libjpeg-turbo:x64-windows-static,在安装后键入。\\ vcpkg集成安装。 The jpeg library will be linked automatically to your project (Restart your VS 2017 and enjoy). jpeg库将自动链接到您的项目(重新启动VS 2017并享受)。

Note that for turbojpeg-static.lib you cannot compile with >VS2010 unless you recompile libjpegturbo yourself... 请注意,对于turbojpeg-static.lib,除非您自己重新编译libjpegturbo,否则不能使用> VS2010进行编译。

I recommend using MinGW for building if you can; 如果可以的话,我建议使用MinGW进行构建。 it is possible to use the turbojpeg static library without issues. 可以毫无问题地使用turbojpeg静态库。

https://github.com/libjpeg-turbo/libjpeg-turbo/issues/45#issuecomment-181690889 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. RE:第一个问题,您可以通过链接legacy_stdio_definitions.lib来解决未解决的_snprintf_s符号错误。 However, the second error ("unresolved external symbol __iob_func") is not easily solvable. 但是,第二个错误(“未解决的外部符号__iob_func”)不容易解决。 It's due to the new "universal C runtime" (ucrt) library that Microsoft introduced recently. 这是由于Microsoft最近引入了新的“通用C运行时”(ucrt)库。 Unfortunately that new library introduces some pretty major incompatibilities with previous Microsoft CRT's. 不幸的是,新库引入了与以前的Microsoft CRT相当大的不兼容性。

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. 参考http://www.libjpeg-turbo.org/Documentation/OfficialBinaries ,由于libjpeg API中的两个函数(jpeg_stdio_dest()和jpeg_stdio_src()要求),因此不可能完全隔离libjpeg-turbo中的CRT。从调用程序向库传递FILE句柄。 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.) 如果libjpeg API库用作DLL(jpeg62.dll),则调用程序必须与jpeg62.dll共享相同的CRT DLL,否则将FILE句柄从一个传递到另一个将不起作用(该FILE指针将指向应用程序或DLL的内存空间中的不透明结构,因此该指针对其他对象将毫无意义。)

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. 传统上,即使使用的Visual C ++版本不同于编译该库的版本,也可以与静态libjpeg-turbo库进行链接,但是显然从未提供支持( https://connect.microsoft.com / VisualStudio / feedback / details / 1144980 / error-lnk2001-unresolved-external-symbol-imp-iob-func ),并且仅由于不同版本的Visual C ++中的CRT相当相似而起作用。 Apparently all of that went out the window with the introduction of the ucrt. 显然,随着ucrt的引入,所有这些都消失了。 Googling the error message reveals that we're far from the only OSS project suffering from this. 对错误消息进行谷歌搜索显示,我们离遭受此困扰的唯一OSS项目还很遥远。

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. 如果使用的是TurboJPEG API,则可以链接到turbojpeg.dll而不是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(). 如果您使用的是libjpeg API,则可以链接到jpeg62.dll而不是jpeg-static.lib,前提是您的应用程序未调用jpeg_stdio_src()或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. 如果需要使用jpeg-static.lib或turbojpeg-static.lib,则需要使用旧版本的Visual C ++生成应用程序,或者使用Visual C ++ 2015生成libjpeg-turbo。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM