Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
dbigham
Posts: 521
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA
Accepted Solution

Undefined reference to jpeg_data_new

Hi,

 

I'm trying to use some code to write EXIF data to a JPEG. Here's my function, which I've adapted from the exif command line tool's actions.c:

 

int ExifHelpers::writeExif(QString fileIn, ExifData* exifData)
{
    JPEGData *jdata;
    unsigned char *d = NULL;
    unsigned int ds;

    /* Parse the JPEG file. */
    jdata = jpeg_data_new();

    // Is this necessary?
    //jpeg_data_log (jdata, log);

    jpeg_data_load_file(jdata, fileIn.toStdString().c_str());

    /* Make sure the EXIF data is not too big. */
    exif_data_save_data (exifData, &d, &ds);
    if (ds)
    {
        free (d);
        if (ds > 0xffff)
        {
            qDebug() << "*** Too much EXIF data.";
        }
    };

    jpeg_data_set_exif_data(jdata, exifData);

    /* Save the modified image. */
    unsigned int bytesWritten;
    jpeg_data_save_file(jdata, fileIn.toStdString().c_str(), &bytesWritten);
    jpeg_data_unref (jdata);

    return 0;
}

 

To my surprise, functions like jpeg_data_new are defined in libexif... in particular:

 

#include <libexif/jpeg-data.h>

 

Here:

 

JPEGData *jpeg_data_new           (void);
JPEGData *jpeg_data_new_from_file (const char *path);
JPEGData *jpeg_data_new_from_data (const unsigned char *data,
				   unsigned int size);

...

 When I compile my program, it complains that the following are undefined:

 

E:\Users\Daniel\Dropbox\Apps\PhotoStar\arm/../src/ExifHelpers.cpp:94: undefined reference to `jpeg_data_new()'
E:\Users\Daniel\Dropbox\Apps\PhotoStar\arm/../src/ExifHelpers.cpp:99: undefined reference to `jpeg_data_load_file(_JPEGData*, char const*)'
E:\Users\Daniel\Dropbox\Apps\PhotoStar\arm/../src/ExifHelpers.cpp:112: undefined reference to `jpeg_data_set_exif_data(_JPEGData*, _ExifData*)'
E:\Users\Daniel\Dropbox\Apps\PhotoStar\arm/../src/ExifHelpers.cpp:116: undefined reference to `jpeg_data_save_file(_JPEGData*, char const*, unsigned int*)'
E:\Users\Daniel\Dropbox\Apps\PhotoStar\arm/../src/ExifHelpers.cpp:117: undefined reference to `jpeg_data_unref(_JPEGData*)'

 

I'm at a loss.

 

I am using other libexif functions in my project, and have been for a long time, without any issue.

 

I've also tried adding libjpeg to my project via the Project -> Configure -> Add Library menu, and that doesn't help.

 

I've tried cleaning my project.  I've tried restarting the IDE.  No luck.

Please use plain text.
Developer
dbigham
Posts: 521
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Undefined reference to jpeg_data_new

By the way, I think the easiest way to reproduce this is to create a new cascades project, and then in applicationui.cpp, add:

 

#include <libexif/jpeg-data.h>

 

...

 

JPEGData* jdata = jpeg_data_new();

 

...

 

... and in the .pro file:

 

LIBS += -lexif

 

... and then compile:

 

E:\Users\Daniel\Dropbox\Apps\CascadesProject\arm/../src/applicationui.cpp:55: undefined reference to `jpeg_data_new()'

Please use plain text.
Developer
dbigham
Posts: 521
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Undefined reference to jpeg_data_new

As answered in another thread, I apparently needed to add:

 

extern "C" { ... }

 

... around the jpeg-data.h include.

Please use plain text.