Include libjpeg-turbo header file included in Qt
-
I built Qt with qjpeg library - which (if I'm not wrong) uses libjpeg-turbo. In my code, I also need to manually call libjpeg-turbo APIs, but I can't find the header file to include that will give me access to libjpeg-turbo apis. It doesn't even exist in the Qt static build folder.
Where can I find it?
-
I figured out the proper way to do this.
In Qt configure command use flag -system-libjpeg, then later specify options:
LIBJPEG_LIBS="<path to release static library file>" [Note: This is full path to jpeg.lib including filename]
-I <path to libjpeg include dir> [Note: This is path to the directory containing include file]@kkoehne You're right, I was able to use release version of libjpeg static lib in my debug program without any issue.
-
If it is (by your configuration options) the Qt default then it will be used by the Qt API calls by default. If you need to call the native API functions directly then you'll need to locate the header file in its system installed location. /usr/include/qjpeg? /usr/local/include/qjpeg?...where it is installed will depend on your system.
If you are on a system that uses pkgconfig then that can help but you need to research how to use it and what if any mods you need to make to your project file.
-
@Kent-Dorfman said in Include libjpeg-turbo header file included in Qt:
your configuration options) the Qt default then it will be used by the Qt API calls by default. If you need to call the native API functions directly then you'll need to locate the header file in its system installed location. /usr/include/qjpeg? /usr/local/include/qjpeg?...where it is installed will depend on your system.
If you are on a system that uses pkgconfig then that can help but you need to research how to use it and what if any mods you need to make to your project file.I'm on windows platform using static Qt build. I searched entire Qt install folder but jpeg library header isn't there. Its only present in Qt sources folder - but that's a different folder from install folder.
-
It's true that Qt bundles an embedded version of libjpeg-turbo. Anyhow, it's not part of the public API, so the header files are not installed when you install Qt, and the libjpeg binary API is AFAIK also not exported.
A proper way to handle this is to build libjpeg yourself locally, independent of Qt. You can then let Qt use this version (pass -system-libjpeg to configure to make sure it picks it up).
-
@Taytoo said in Include libjpeg-turbo header file included in Qt:
On windows, how do I provide path of my libjpeg lib/headers when using -system-libjpeg option?
There are different options:
- Extend the INCLUDE, LIBS environment variables with the respective directories
- pass the respective directories to configure via -I, -L configure arguments
-
Either copy them into one directory or use this qmake construct: https://doc.qt.io/qt-5/qmake-test-function-reference.html#config-config
-
@Christian-Ehrlicher Wouldn't just copying the jpeg lib result in build errors? Because if I build Qt by specifying path to release version of libjpeg, but then try to build my program in debug mode - msvc will complain about debug vs release crt runtime conflict. Reason being my program + qt libraries will be using debug crt runtime, but libjpeg will be referencing the release one.
Found this: https://forum.qt.io/topic/75056/configuring-qt-what-replaces-debug-and-release/
This guy had the same issue as mine. He built two versions of Qt, one debug and other release in separate folders, But installed them into a single folder. That way he got both builds using correct release and debug 3rd party libraries as well. What about this approach?
-
On Windows the debug library normally has a 'd' suffix to distinguish between debug and release libs so you don't override them by copying. If you don't like to coy it, use the qmake function.
-
@Christian-Ehrlicher Can you explain the copy approach i.e. just copy the libjpeg I built (both debug and release) into existing Qt lib folder? or should I build Qt using those versions? If later, then how do I ensure that debug and release builds of Qt reference the appropriate debug/release version of libjpeg?
I'm using MSVC for building, how do I use qmake?
-
@Taytoo said in Include libjpeg-turbo header file included in Qt:
I have debug and release versions of libjpeg-turbo in separate folders. How do I specify correct folder for each Qt build i.e. debug and release?
You mean you want to do a combined -debug-and-release build? I don't think that's easily possible, because Qt will always assume the library is called 'libjpeg.lib'. The approach @Christian-Ehrlicher refers to works though for the part where you link against libjpeg yourself, in your app.
Anyhow, do you really need a separate debug build of libjpeg? AFAIK libjpeg is C API only, in which case there's no problem with linking a release build of libjpeg also with a debug build of Qt libraries.
-
I figured out the proper way to do this.
In Qt configure command use flag -system-libjpeg, then later specify options:
LIBJPEG_LIBS="<path to release static library file>" [Note: This is full path to jpeg.lib including filename]
-I <path to libjpeg include dir> [Note: This is path to the directory containing include file]@kkoehne You're right, I was able to use release version of libjpeg static lib in my debug program without any issue.
-
@Houda_ATTIG said in Include libjpeg-turbo header file included in Qt:
I am a beginner with Qt can you please tell me how to build libjpeg myself locally?
Building libjepeg has nothing to do with Qt.
Download libjpeg source code (https://sourceforge.net/projects/libjpeg/) and read install.doc file included in the source code archive. -
First of all thanks for your answer.
well I am using windows 10 with Qt creator, which files am I supposed to choose?Makefile jconfig file System and/or compiler
makefile.manx jconfig.manx Amiga, Manx Aztec C
makefile.sas jconfig.sas Amiga, SAS C
makeproj.mac jconfig.mac Apple Macintosh, Metrowerks CodeWarrior
makjpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C
makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C
makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C)
makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only)
makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C
makefile.vc jconfig.vc Windows, MS Visual C++
makefile.vs jconfig.vc Windows, MS Visual C++ 6 Developer Studio
make.vc6
makefile.vs jconfig.vc Windows, Visual Studio 2019 (v16)
make*.v16
makefile.b32 jconfig.vc Windows, Borland C++ 32-bit (bcc32)
makefile.mms jconfig.vms Digital VMS, with MMS software
makefile.vms jconfig.vms Digital VMS, without MMS software -
@Houda_ATTIG Probably
makefile.vc jconfig.vc Windows NT/95, MS Visual C++
But you will need MSVC++ compiler.
-
Use this: https://github.com/microsoft/vcpkg
vcpkg allows your to build 100s of open source libraries with a single command e.g. ".\vcpkg install libjpeg-turbo". It also copies header and lib files to a specific folder that you only need to include once in your project.
Make the effort to get familiar with vcpkg, it will save you a lot of time trying to build/use open source libraries.