Welcome! Log In Create A New Profile

Advanced

libjpeg problems...

Posted by DrTwox 
libjpeg problems...
November 29, 2008 08:09AM
Hi all,

I apologise in advance for the messy state of this post - but I really don't know where to begin...

I've installed the libjpeg-wii-gc library into my libogc directory, #included jpeglib.h in my project, but I get this error when I compile:

In file included from /opt/devkitPRO//libogc/include/jpeg/jpeglib.h:26,
from /home/drtwox/C/Wii/wiimp/source/libgfx.c:9:
/opt/devkitPRO//libogc/include/jpeg/jmorecfg.h:227: error: conflicting types for 'u8'
/opt/devkitPRO//libogc/include/gctypes.h:22: error: previous declaration of 'u8' was here

jmorecfg.h:
/*
 * On a few systems, type boolean and/or its values FALSE, TRUE may appear
 * in standard header files.  Or you may have conflicts with application-
 * specific header files that you want to include together with these files.
 * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
 */

#ifndef HAVE_BOOLEAN
typedef int boolean;            /* THIS IS LINE 227 HERE */
#endif
#ifndef FALSE			/* in case these macros already exist */
#define FALSE	0		/* values of boolean */
#endif
#ifndef TRUE
#define TRUE	1
#endif
gctypes line 22:
typedef unsigned char u8;
How is line 227 of jmorecfg.h and line 22 of gctypes conflicting?

If I follow the advice in jmorecfg.h and put "#define HAVE_BOOLEAN" before including jpeglib.h, I get a crash when calling jpeg_create_decompress(&cinfo);

I am able to compile and load other people's projects that use libjpeg, so I'm totally stumped as to what's wrong. Any ideas? (Note: I don't want to use the JPEG_Decompress wrapper in jpgogc.h - it's too limited for my purposes)

Edit 1: Well I removed the #include for gctypes and that fixed that problem, but now the linker is having problems:

linking ... wiimp.elf
libgfx.o: In function `SpriteFromJPG':
/home/drtwox/C/Wii/wiimp/source/libgfx.c:640: undefined reference to `jpeg_memory_src'

How can jpeg_memory_src not work in my app, but the libjpeg test app, which uses the same function through JPEG_Decompress, compiles just fine?

Edit 2: Removing gctypes from the includes isn't a solution to the first problem, as certain libogc headers include it too, making it's inclusion unavoidable...



Edited 2 time(s). Last edit at 11/29/2008 09:48AM by DrTwox.
Re: libjpeg problems...
November 29, 2008 04:21PM
Quote

How is line 227 of jmorecfg.h and line 22 of gctypes conflicting?

In gctypes.h, there's a "#define boolean u8", which would explain the conflict.

When you get the crash, is this after deleting all your project's object files and recompiling?
Re: libjpeg problems...
November 30, 2008 01:03AM
Yeah, even with a 'make clean' the crash happens. Here's what I've discovered so far...

* My main app (WiiMP) already uses the jpeg functions without the jpgogc wrapper, WITHOUT ANY ERRORS; this is what has me confused. I'm trying to "port" the jpeg functions from my graphics code to GRRLIB, so users of that library can benefit from proper jpg support. It's this GRRLIB port that is causing the errors.

* Using libjpeg from the SDL-port fixes the "undefined reference to `jpeg_memory_src'" error.

* If I use "#define HAVE_BOOLEAN" before including jpeglib.h I can compile, but the Wii will crash as soon as jpeg_create_decompress(&cinfo) is called.

* If I don't use #define HAVE_BOOLEAN the compiler will stop with the "conflicting types" error from my first post, and I'm not sure what I need to change in libjpeg to fix the problem.

* Basically, It *seems* if I can get away without including gctypes.h before jpeglib.h, it will compile and work... but not having gctypes.h #included somewhere along the way is almost impossible... (yet I managed it in WiiMP, which is a miracle!)

... or it's entirely possible I'm doing something totally wrong, or completely overlooking the obvious!
Re: libjpeg problems...
November 30, 2008 03:18AM
You can do something like this maybe to work around the conflicting type issue:

#include <gctypes.h>
#undef boolean
#include <jpeglib.h>
#define boolean u8

I wouldn't expect the HAVE_BOOLEAN method to work, since you're changing the size of boolean from a 32-bit type in your jpeg header to an 8-bit type in gctypes.h. That would cause problems with function calls and structure references, I would think, unless you recompiled libjpeg with this new boolean type.
Re: libjpeg problems...
November 30, 2008 04:25AM
Thanks for the suggestion, I'll try it out.

Quote

...since you're changing the size of boolean from a 32-bit type in your jpeg header...

That's what I don't understand; it's not MY header, it's the libjpeg standard header. Why has this issue not come up before with other projects using libjpeg?
Re: libjpeg problems...
November 30, 2008 05:02AM
I think my last suggestion is solving the issue the wrong way around. Looking closer at what's in gctypes.h, it first checks if 'boolean' is defined before defining its own version. So the better solution, and likely why this hasn't come up before, is simply to include jpeglib.h before gctypes.h. I hope that works.
Re: libjpeg problems...
November 30, 2008 03:00PM
I am testing this out from DrTwox post on GGRLIB and have managed to get it working!

All I did was take a bit of Michels advice and added this before including jpeglib.h

#undef boolean

This enable the define in jpeglib.h to override the existing on defined in gctypes and all seems to work alright still!
Sorry, only registered users may post in this forum.

Click here to login