[solved] Problem to link with libjpeg

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
bronsky
Posts: 12
Joined: Sun Dec 24, 2006 5:36 am
Location: Paris

[solved] Problem to link with libjpeg

Post by bronsky »

Hello,

I searched the net and also this forum about this, i really don't understand what's happening...

I can't get to link with libjpeg (undefined references...). I've reduced the problem to a very little program that simply includes jpeglib.h and instanciates a decompression object. Of course, I link with -ljpeg. Here is the program:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <pspkernel.h>
#include <jpeglib.h>

PSP_MODULE_INFO&#40;"Test", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;


int main&#40;int argc, char **argv&#41;
&#123;
        struct jpeg_decompress_struct cinfo;
        jpeg_create_decompress&#40;&cinfo&#41;;

        return 0;
&#125;
Here is the Makefile:

Code: Select all

TARGET = Tetris
OBJS = main.o

INCDIR =
LIBDIR =
LDFLAGS =
LIBS = -ljpeg -lstdc++ -lpsprtc
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test
KXDIR = __SCE__$&#40;TARGET&#41;
KXDUMMY = %__SCE__$&#40;TARGET&#41;

PSPSDK = $&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
And finally the compilation output:

Code: Select all

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-rtti   -c -o main.o main.cpp
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall  -L. -L/usr/local/pspdev/psp/sdk/lib   main.o -ljpeg -lstdc++ -lpsprtc -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o Tetris.elf
main.o&#58; In function `main'&#58;
main.cpp&#58;&#40;.text+0x10&#41;&#58; undefined reference to `jpeg_CreateDecompress&#40;jpeg_decompress_struct*, int, unsigned int&#41;'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;Tetris.elf&#93; Error 1

I've verified, by removing them, that the compiler takes the right jpeglib.h and libjpeg.a files. My libjpeg comes from a compilation of svn://svn.pspdev.org/psp/trunk/jpeg checked out this evening.

Did anyone already have some link problems with libjpeg ?? I haven't had any such problem when I used zlib and libpng...

Thanks in advance
Last edited by bronsky on Sat Feb 17, 2007 9:11 am, edited 1 time in total.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Your code and Makefile compile just fine here. Maybe your libjpeg build was bad? Try "make clean" followed by "make" and "make install" in the libjpeg dir, paste the output here. Also try "psp-nm /usr/local/pspdev/psp/lib/libjpeg.a | grep -i create"
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Code: Select all

jpeg_CreateDecompress
Is not the same as:

Code: Select all

jpeg_createdecompress
bronsky
Posts: 12
Joined: Sun Dec 24, 2006 5:36 am
Location: Paris

Post by bronsky »

Insert_witty_name wrote:

Code: Select all

jpeg_CreateDecompress
Is not the same as:

Code: Select all

jpeg_createdecompress
Yeah I had noticed this too, you can see the explanation in the header:

Code: Select all

/* Initialization of JPEG compression objects.
 * jpeg_create_compress&#40;&#41; and jpeg_create_decompress&#40;&#41; are the exported
 * names that applications should call.  These expand to calls on
 * jpeg_CreateCompress and jpeg_CreateDecompress with additional information
 * passed for version mismatch checking.
 * NB&#58; you must set up the error-manager BEFORE calling jpeg_create_xxx.
 */
#define jpeg_create_compress&#40;cinfo&#41; \
    jpeg_CreateCompress&#40;&#40;cinfo&#41;, JPEG_LIB_VERSION, \
                        &#40;size_t&#41; sizeof&#40;struct jpeg_compress_struct&#41;&#41;
#define jpeg_create_decompress&#40;cinfo&#41; \
    jpeg_CreateDecompress&#40;&#40;cinfo&#41;, JPEG_LIB_VERSION, \
                          &#40;size_t&#41; sizeof&#40;struct jpeg_decompress_struct&#41;&#41;
jimparis, here is what a "psp-nm /usr/local/pspdev/psp/lib/libjpeg.a | grep -i create" gives me... not surprisingly, unfortunately:
bronsky@athlon2400:~$ psp-nm /usr/local/pspdev/psp/lib/libjpeg.a |grep -i create
00000000 T jpeg_CreateCompress
00000000 T jpeg_CreateDecompress
0000002c t create_colorindex
So nm can see the stuff, but not ld... really can't figure it out :(
I've also added some --verbose in the makefile, which gives the following output (nothing interesting in my opinion but maybe you'll see something...):

Code: Select all

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include --verbose -O2 -G0 -Wall -I. -I/usr/local/pspdev/psp/sdk/include --verbose -O2 -G0 -Wall --verbose -fno-rtti   -c -o main.o main.cpp
Using built-in specs.
Target&#58; psp
Configured with&#58; ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model&#58; single
gcc version 4.0.2 &#40;PSPDEV 20051022&#41;
 /usr/local/pspdev/libexec/gcc/psp/4.0.2/cc1plus -quiet -v -v -v -I. -I/usr/local/pspdev/psp/sdk/include -I. -I/usr/local/pspdev/psp/sdk/include -DPSP=1 -D__psp__=1 -D_PSP=1 main.cpp -G0 -G0 -quiet -dumpbase main.cpp -auxbase-strip main.o -O2 -O2 -Wall -Wall -version -fno-rtti -o /tmp/cc55U6Ie.s
ignoring nonexistent directory "/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/sys-include"
ignoring duplicate directory "."
ignoring duplicate directory "/usr/local/pspdev/psp/sdk/include"
#include "..." search starts here&#58;
#include <...> search starts here&#58;
 .
 /usr/local/pspdev/psp/sdk/include
 /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../include/c++/4.0.2
 /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../include/c++/4.0.2/psp
 /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../include/c++/4.0.2/backward
 /usr/local/pspdev/lib/gcc/psp/4.0.2/include
 /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/include
End of search list.
GNU C++ version 4.0.2 &#40;PSPDEV 20051022&#41; &#40;psp&#41;
        compiled by GNU C version 4.1.2 20060928 &#40;prerelease&#41; &#40;Ubuntu 4.1.1-13ubuntu5&#41;.
GGC heuristics&#58; --param ggc-min-expand=81 --param ggc-min-heapsize=96948
 /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/bin/as -G0 -G0 -EL -O2 -no-mdebug -mabi=eabi -v -v -v -mno-pdr -o main.o /tmp/cc55U6Ie.s
GNU assembler version 2.16.1 &#40;psp&#41; using BFD version 2.16.1 &#40;PSPDEV 20060116&#41;
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include --verbose -O2 -G0 -Wall  -L. -L/usr/local/pspdev/psp/sdk/lib --verbose  main.o -ljpeg -lstdc++ -lpsprtc -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o Tetris.elf
Using built-in specs.
Target&#58; psp
Configured with&#58; ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model&#58; single
gcc version 4.0.2 &#40;PSPDEV 20051022&#41;
 /usr/local/pspdev/libexec/gcc/psp/4.0.2/collect2 -EL -G0 -o Tetris.elf /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/crt0.o /usr/local/pspdev/lib/gcc/psp/4.0.2/crti.o /usr/local/pspdev/lib/gcc/psp/4.0.2/crtbegin.o -L. -L/usr/local/pspdev/psp/sdk/lib -L/usr/local/pspdev/lib/gcc/psp/4.0.2 -L/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib main.o -ljpeg -lstdc++ -lpsprtc -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lgcc -lgcc /usr/local/pspdev/lib/gcc/psp/4.0.2/crtend.o /usr/local/pspdev/lib/gcc/psp/4.0.2/crtn.o
main.o&#58; In function `main'&#58;
main.cpp&#58;&#40;.text+0x10&#41;&#58; undefined reference to `jpeg_CreateDecompress&#40;jpeg_decompress_struct*, int, unsigned int&#41;'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;Tetris.elf&#93; Error 1
Two things however:
- is it normal that this output mentions consecutively 2 different version of pspdev ? (PSPDEV 20051022 then PSPDEV 20060116 then PSPDEV 20051022 again)
- i supposed that when it says "ld returned 1" it actually means "psp-ld" ? is there any way to check that ? (but i suppose that if it was wrong i wouldn't have compiled all my previous programs...)

Thanks
Bronsky
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Oh, you didn't mention that you were using C++.
Name your file main.c and it will work fine.
Probably jpeg.h needs an "extern C" block around it.
bronsky
Posts: 12
Joined: Sun Dec 24, 2006 5:36 am
Location: Paris

Post by bronsky »

Yes indeed I forgot to mention that and you're right, it was the point ! An "extern C" around the inclusion solved the problem... Thanks for your patience, c u !
Post Reply