PDA

View Full Version : Cannot link against jpeglib and turbojpeg in QtCreator project



donelron
20th September 2015, 23:54
Dear all,

I have the following minimal working example in QtCreator in which I am trying to use Qt together with libjpeg and libjpeg-turbo:

Appplication.pro:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Application
TEMPLATE = app


SOURCES += main.cpp\

main.cpp:


#include <QFile>

#include <turbojpeg.h>
#include <jpeglib.h>

int main(int argc, char *argv[])
{
// Step 1: disk to qbytearray
QFile file("example.jpg");
file.open(QIODevice::ReadOnly);
QByteArray blob = file.readAll();
file.close();


// Step 2: Trying to use what's declared in jpeglib.h in order to decompress the file which was just read
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
//...... if the above lines worked, some more code would be added here ....


// Step 3: Trying to use what's declared in turbojpeg.h
long unsigned int _jpegSize;
unsigned char* _compressedImage;

int jpegSubsamp, width, height;
unsigned char buffer[width*height*3]; //!< will contain the decompressed image

tjhandle _jpegDecompressor = tjInitDecompress();
//...... if the above lines worked, some more code would be added here ....

return 0;
}



Files turbojpeg.h and jpeglib.h are both included in /usr/include on my computer (running Debian Jessie). If I dpkg -l *jpeg*, then I get the following. It's in german, but I guess everybody will be able to figure out, what it means.


Gewünscht=Unbekannt/Installieren/R=Entfernen/P=Vollständig Löschen/Halten
| Status=Nicht/Installiert/Config/U=Entpackt/halb konFiguriert/
Halb installiert/Trigger erWartet/Trigger anhängig
|/ Fehler?=(kein)/R=Neuinstallation notwendig (Status, Fehler: GROSS=schlecht)
||/ Name Version Architektur Beschreibung
+++-==============================-====================-====================-================================================== ===============
un libjpeg-dev <keine> <keine> (keine Beschreibung vorhanden)
un libjpeg-progs <keine> <keine> (keine Beschreibung vorhanden)
ii libjpeg-turbo-progs 1:1.3.1-12 amd64 Programs for manipulating JPEG files
un libjpeg-turbo8 <keine> <keine> (keine Beschreibung vorhanden)
un libjpeg62 <keine> <keine> (keine Beschreibung vorhanden)
un libjpeg62-dbg <keine> <keine> (keine Beschreibung vorhanden)
un libjpeg62-dev <keine> <keine> (keine Beschreibung vorhanden)
ii libjpeg62-turbo:amd64 1:1.3.1-12 amd64 libjpeg-turbo JPEG runtime library
ii libjpeg62-turbo-dbg:amd64 1:1.3.1-12 amd64 Debugging symbols for the libjpeg-turbo JPEG library
ii libjpeg62-turbo-dev:amd64 1:1.3.1-12 amd64 Development files for the libjpeg-turbo JPEG library
un libjpeg7-dev <keine> <keine> (keine Beschreibung vorhanden)
un libjpeg8-dev <keine> <keine> (keine Beschreibung vorhanden)
un libjpeg9-dev <keine> <keine> (keine Beschreibung vorhanden)
ii libopenjpeg5:amd64 1:1.5.2-3 amd64 JPEG 2000 image compression/decompression library - runtime
un libturbojpeg <keine> <keine> (keine Beschreibung vorhanden)
ii libturbojpeg1:amd64 1:1.3.1-12 amd64 TurboJPEG runtime library - SIMD optimized


In addition, I also compiled libjpeg-turbo-1.4.1 from source as is described here: http://igor-zivkovic.from.hr/BLFS/general/libjpeg.html
I don't know why I did that... Maybe I was just desperate and did not know, what else to do to get it working ;) ...

I am using compiler GCC for 64 bit, which QtCreator auto-detected in /usr/bin.
Compiling the above project gives the following error results:



/home/ron/QtCreator/MWElibjpegForQtForum/Application/main.cpp:18: error: undefined reference to `jpeg_std_error'
/home/ron/QtCreator/MWElibjpegForQtForum/Application/main.cpp:19: error: undefined reference to `jpeg_CreateDecompress'
/home/ron/QtCreator/MWElibjpegForQtForum/Application/main.cpp:30: error: undefined reference to `tjInitDecompress'


I can see in turbojpeg.h that the header seems to be compiled for Windows, as it starts with:

#if defined(_WIN32) && defined(DLLDEFINE)
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#define DLLCALL

However, this is not consistent with the typical approach which I have seen a couple of times in tutorials, etc. such as here: https://www.ibm.com/developerworks :/aix/library/au-porting/ (https://www.ibm.com/developerworks/aix/library/au-porting/)

#ifdef DLLDEFINE
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif

So, I am kind of confused how the two libs were supposed to be used...

Does anybody have an idea how to get this thing working? Your help is very much appreciated. Thanks!

anda_skoa
21st September 2015, 09:04
I am using compiler GCC for 64 bit, which QtCreator auto-detected in /usr/bin.
Compiling the above project gives the following error results:



/home/ron/QtCreator/MWElibjpegForQtForum/Application/main.cpp:18: error: undefined reference to `jpeg_std_error'
/home/ron/QtCreator/MWElibjpegForQtForum/Application/main.cpp:19: error: undefined reference to `jpeg_CreateDecompress'
/home/ron/QtCreator/MWElibjpegForQtForum/Application/main.cpp:30: error: undefined reference to `tjInitDecompress'


The linker complains that there are certain symbols used by your program that it can't find anywhere.
You are using functions that your program does not provide itself but you are also not linking to any libraries that would provide these.

You need to specify their path and name in the .pro file, using the LIBS variable.

Cheers,
_

donelron
27th September 2015, 21:44
Sorry for not answering for some time. Unfortunately I just could not make some free time to deal with this thing....
I opened my .pro file and used rightclick->Add library-> internal library to add. I think, that especially for someone who is rather new to QtCrator this is easier...
Thanks for your help!!!