forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[solved] Problem to link with libjpeg

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
bronsky



Joined: 24 Dec 2006
Posts: 12
Location: Paris

PostPosted: Thu Feb 15, 2007 9:00 am    Post subject: [solved] Problem to link with libjpeg Reply with quote

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:

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

PSP_MODULE_INFO("Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);


int main(int argc, char **argv)
{
        struct jpeg_decompress_struct cinfo;
        jpeg_create_decompress(&cinfo);

        return 0;
}


Here is the Makefile:
Code:
TARGET = Tetris
OBJS = main.o

INCDIR =
LIBDIR =
LDFLAGS =
LIBS = -ljpeg -lstdc++ -lpsprtc
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test
KXDIR = __SCE__$(TARGET)
KXDUMMY = %__SCE__$(TARGET)

PSPSDK = $(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


And finally the compilation output:

Code:
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: In function `main':
main.cpp:(.text+0x10): undefined reference to `jpeg_CreateDecompress(jpeg_decompress_struct*, int, unsigned int)'
collect2: ld returned 1 exit status
make: *** [Tetris.elf] 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
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Feb 15, 2007 11:56 am    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Thu Feb 15, 2007 3:33 pm    Post subject: Reply with quote

Code:
jpeg_CreateDecompress


Is not the same as:

Code:
jpeg_createdecompress
Back to top
View user's profile Send private message
bronsky



Joined: 24 Dec 2006
Posts: 12
Location: Paris

PostPosted: Fri Feb 16, 2007 10:00 am    Post subject: Reply with quote

Insert_witty_name wrote:
Code:
jpeg_CreateDecompress

Is not the same as:
Code:
jpeg_createdecompress

Yeah I had noticed this too, you can see the explanation in the header:
Code:
/* Initialization of JPEG compression objects.
 * jpeg_create_compress() and jpeg_create_decompress() 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: you must set up the error-manager BEFORE calling jpeg_create_xxx.
 */
#define jpeg_create_compress(cinfo) \
    jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
                        (size_t) sizeof(struct jpeg_compress_struct))
#define jpeg_create_decompress(cinfo) \
    jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
                          (size_t) sizeof(struct jpeg_decompress_struct))


jimparis, here is what a "psp-nm /usr/local/pspdev/psp/lib/libjpeg.a | grep -i create" gives me... not surprisingly, unfortunately:
Quote:
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:
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: psp
Configured with: ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model: single
gcc version 4.0.2 (PSPDEV 20051022)
 /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:
#include <...> search starts here:
 .
 /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 (PSPDEV 20051022) (psp)
        compiled by GNU C version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5).
GGC heuristics: --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 (psp) using BFD version 2.16.1 (PSPDEV 20060116)
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: psp
Configured with: ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model: single
gcc version 4.0.2 (PSPDEV 20051022)
 /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: In function `main':
main.cpp:(.text+0x10): undefined reference to `jpeg_CreateDecompress(jpeg_decompress_struct*, int, unsigned int)'
collect2: ld returned 1 exit status
make: *** [Tetris.elf] 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
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Fri Feb 16, 2007 6:18 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
bronsky



Joined: 24 Dec 2006
Posts: 12
Location: Paris

PostPosted: Sat Feb 17, 2007 9:04 am    Post subject: Reply with quote

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 !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group