stdlib.h & malloc.h : when & why...

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

stdlib.h & malloc.h : when & why...

Post by Shazz »

Usually, while using pspsdk makefiles, including stdlib.h is enough to define malloc and free

But now, as I'm recompiling a portable 3rd party library using generated makefiles, malloc is undefined if malloc.h is not explicitly added (which is not portable, so I had to patch the code)

Can somebody explain me why ?

Code: Select all

if psp-gcc -G0 -DHAVE_CONFIG_H -I. -I. -I..   -DHAVE_CONFIG_CONFIG68_H=1 -DNO_FALLBACK_CONFIG=1 -Wall -O3 -fomit-frame-pointer  -I/usr/local
/pspdev/psp/sdk/include/libc -I/usr/local/pspdev/psp/sdk/include -I/usr/local/pspdev/psp/include -DHAVE_CONFIG_CONFIG68_H=1 -DNO_FALLBACK_CO
NFIG=1 -Wall -O3 -fomit-frame-pointer -MT word.o -MD -MP -MF ".deps/word.Tpo" \
  -c -o word.o `test -f 'word.c' || echo './'`word.c; \
then mv -f ".deps/word.Tpo" ".deps/word.Po"; \
else rm -f ".deps/word.Tpo"; exit 1; \
fi
word.c: In function 'strsav':
word.c:83: warning: implicit declaration of function 'malloc'
word.c:83: warning: incompatible implicit declaration of built-in function 'malloc'
word.c: In function 'delete_word_list':
word.c:96: warning: implicit declaration of function 'free'
/bin/sh ../libtool --mode=link psp-gcc -G0  -I/usr/local/pspdev/psp/sdk/include/libc -I/usr/local/pspdev/psp/sdk/include -I/usr/local/pspdev
/psp/include -DHAVE_CONFIG_CONFIG68_H=1 -DNO_FALLBACK_CONFIG=1 -Wall -O3 -fomit-frame-pointer  -L/usr/local/pspdev/psp/sdk/lib -lz -lc -lpsp
libc  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsputility -lpspuser -lpspkernel -o as68  as68.o error.o expression.o opcode.o wo
rd.o
word.c includes

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "as68.h"
thanks
- TiTAN Art Division -
http://www.titandemo.org
benji
Posts: 17
Joined: Fri Oct 14, 2005 2:41 pm

Post by benji »

My first guess would be that it's pulling in the wrong stdlib.h file... try adding the -nostdinc flag to your CFLAGS to eliminate that possibility.

benji
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

Ok found, it was due to this include : -I/usr/local
/pspdev/psp/sdk/include/libc as the pspsdk libc doesn't implement malloc

Is it something missing ? Who's working on the pspsdk libc ? Maybe I can help...
- TiTAN Art Division -
http://www.titandemo.org
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

*Sigh*. For any serious use of the ANSI C library, don't use PSPSDK's libc. Use newlib's libc.
71M
Posts: 122
Joined: Tue Jun 21, 2005 5:28 am
Location: London

Post by 71M »

Is this true for PRX compilation as well?
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

It should but it seems newlib libc is not supported by the pspsdk PRX... (see raf posts)
- TiTAN Art Division -
http://www.titandemo.org
Post Reply