How to compile libxml2

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

Moderators: cheriff, TyRaNiD

Post Reply
mokke
Posts: 1
Joined: Wed Jun 04, 2008 1:02 am

How to compile libxml2

Post by mokke »

Hi,

im trying to compile libxml2 for psp. but i cant compile libxml2 for psp.
ive seen the past topic about xml in this forum. and i tried to compile libxml2.
but failed. so i need help.

what i did :
install pspsdk, psplibraries.
download libxml2-2.6.32
compile libxml2 following below code. ... failed!

os : ubuntu

Code: Select all

CC=psp-gcc CXX=psp-g++ LIBS="-lpspdebug -lpspdisplay -lpspge -lc -lpspuser -lpspkernel" LDFLAGS="-L/usr/local/pspdev/psp/sdk/lib" ./configure --host=mips --with-minimum --without-threads --without-writer --without-modules
make 
but make stops with below error.

Code: Select all

...
... ....
/.libs/libxml2.a(encoding.o): In function `xmlAddEncodingAlias':
/home/student/Desktop/libxml2-2.6.32/encoding.c:1000: relocation truncated to fit: R_MIPS_GPREL16 against `__ctype_ptr'
./.libs/libxml2.a(encoding.o): In function `xmlGetEncodingAlias':
/home/student/Desktop/libxml2-2.6.32/encoding.c:969: relocation truncated to fit: R_MIPS_GPREL16 against `__ctype_ptr'
./.libs/libxml2.a(encoding.o): In function `xmlParseCharEncoding':
/home/student/Desktop/libxml2-2.6.32/encoding.c:1106: relocation truncated to fit: R_MIPS_GPREL16 against `__ctype_ptr'
./.libs/libxml2.a(encoding.o): In function `xmlNewCharEncodingHandler':
/home/student/Desktop/libxml2-2.6.32/encoding.c:1270: relocation truncated to fit: R_MIPS_GPREL16 against `__ctype_ptr'
./.libs/libxml2.a(encoding.o): In function `xmlFindCharEncodingHandler':
/home/student/Desktop/libxml2-2.6.32/encoding.c:1598: relocation truncated to fit: R_MIPS_GPREL16 against `__ctype_ptr'
collect2: ld returned 1 exit status
make[2]: *** [xmllint] Error 1
make[2]: Leaving directory `/home/gsus/libxml/libxml2-2.6.24'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/gsus/libxml/libxml2-2.6.24'
make: *** [all] Error 2 
do i need to add other code now? please help me.

Regards, mokke
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

It's a big pain in the rear... here's how I did it.

Check out the latest libxml2 from their svn repo, or get an archive.

Edit Makefile.am: add "dup.c" after "xmlIO.c" on line 35.

Create a file in the libxml2 directory called "dup.c" and give it these contents:

Code: Select all

#include <fcntl.h>

int
dup &#40;int fd1&#41; &#123;
	return &#40;fcntl &#40;fd1, F_DUPFD, 0&#41;&#41;;
&#125;
Run

Code: Select all

./autogen.sh
Now edit config.sub: add

Code: Select all

	psp&#41;
		basic_machine=mipsallegrexel-psp
		os=-elf
		;;
at line 883 (should be immediately after ps2 entry).

Now run

Code: Select all

CFLAGS="-g -O2 -G0 -Wall" LDFLAGS="-L$&#40;psp-config --psp-prefix&#41;/lib -L$&#40;psp-config --pspsdk-path&#41;/lib"   LIBS="-lz -lc -lstdc++ -lpsplibc -lpspuser -lpspnet_inet -lpspnet_resolver"   ./configure --host=psp --disable-shared --prefix=$&#40;psp-config --psp-prefix&#41;
Now you're ready to "make". It should error out on "runtest.c". If so, you've got what you want. The tests are extraneous... I don't know WHY the official build tries to do them by default.

Now "make install". It'll again error out on the test. Now you have to complete the install by hand (you only got the includes).

Copy ".libs/libxml2.a" to "/usr/local/pspdev/psp/lib/".
Copy "libxml2.la" to "/usr/local/pspdev/psp/lib/".
Copy "libxml-2.0.pc" to "/usr/local/pspdev/psp/lib/pkgconfig/".

And you're done.

A couple thoughts: Only the i386 has dup() in newlib... does no one use it anymore? Was it moved somewhere else on other platforms? The dup.c above is from that i386 code. libxml2 relies on dup()... it's got to be SOMEWHERE. Either dup() and dup2() where moved out of newlib to someplace else (that doesn't exist on the PSP), or no one uses the svn version of libxml2. Secondly, why the hell do they try to compile AND RUN the tests by default? It should only do that if you tell it to. "make tests" for example. It's ridiculous that the default build makes every test known the mankind AND tries to run them. Finally, this library is HUGE. Is there a smaller xml library? Not tinyxml... that's C++. I mean a C lib for xml.

EDIT: to answer my last question, it looks like mini-xml might be better for xml on the PSP. I'll have to try it.

http://www.minixml.org/
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

As a follow-up, I was able to successfully compile and test mini-xml. You need to configure with this:

Code: Select all

CFLAGS="-G0" LDFLAGS="-L$&#40;psp-config --psp-prefix&#41;/lib -L$&#40;psp-config --pspsdk-path&#41;/lib"   LIBS="-lc -lstdc++ -lpsplibc -lpspuser"   ./configure --host=psp --disable-shared --disable-threads --prefix=$&#40;psp-config --psp-prefix&#41;
Then it'll compile. Like libxml2, this tries to compile a test app, which fails since we're cross-compiling. Folks just don't take that into consideration, do they?

You have to copy the lib and include file by hand, naturally.

I altered the test app to run on the PSP and tried it... works fine.
kralyk
Posts: 114
Joined: Sun Apr 06, 2008 8:18 pm
Location: Czech Republic, central EU

Post by kralyk »

Are you sure you need libxml2?
There is a parser called TinyXML, dunno if you know about it, it can be found here:
http://sourceforge.net/projects/tinyxml

I know it works on psp, I have seen is in bookr.
Id recomend you looking into bookr sources here:
http://sourceforge.net/projects/bookr/
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

TinyXML is C++ only, not C. Mini-XML is C or C++, so it's better for the PSP.
kralyk
Posts: 114
Joined: Sun Apr 06, 2008 8:18 pm
Location: Czech Republic, central EU

Post by kralyk »

Why is C better for psp than C++ ?
(just curious...)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

kralyk wrote:Why is C better for psp than C++ ?
(just curious...)
Because it is. :P :D

What I mean is that many programs are C, not C++. You can't use a C++ library in a C program. Most programmers writing in C don't want to switch to C++ just to use XML. They're using C instead of C++ for a reason, and forcing them to switch to C++ just for one library is silly. So if your project is already C++, TinyXML is fine, but if your project is C, don't switch, use Mini-XML.
User avatar
uberjack
Posts: 34
Joined: Tue Jul 17, 2007 9:09 am
Location: California, USA
Contact:

Post by uberjack »

J.F. wrote:
kralyk wrote:Why is C better for psp than C++ ?
(just curious...)
Because it is. :P :D

What I mean is that many programs are C, not C++. You can't use a C++ library in a C program. Most programmers writing in C don't want to switch to C++ just to use XML. They're using C instead of C++ for a reason, and forcing them to switch to C++ just for one library is silly. So if your project is already C++, TinyXML is fine, but if your project is C, don't switch, use Mini-XML.
Yeah, but turning a C program into a C++ program is quite a simple task ;)
Granted, we're warned against using standard C libraries in C++, but who listens to warnings these days?

Actually, I do agree with J.F. if only because C is ubiquitous in the PSP community
Post Reply