#6821 - tangl_99 - Tue Jun 03, 2003 3:55 am
Although the complier does not report errors,
The 'malloc' does not work !
Help!
#6828 - Quirky - Tue Jun 03, 2003 7:47 am
But does the linker report errors? And in what way doesn't it work? How much memory are you trying to allocate? Devkit Advance's malloc works "out the box" IME, you shouldn't have to do anything special.
#6842 - MojoJojo - Tue Jun 03, 2003 12:11 pm
You're not mixing malloc and new are you? That always messes things up.
Remember that by default, the compiler will try and allocate everything in IWRAM (uh, Im not absolutely sure on this but I think that's right), and you only have 32k of that, so trying to allocate a big arrays won't work.
Without knowing anymore about your problem it's hard to know what could be going wrong, but I guess it's a pointer problem as opposed to a problem with malloc.
#6867 - Jason Wilkins - Tue Jun 03, 2003 8:31 pm
The default new operator uses malloc and the default delete uses free. It will not get messed up unless you delete something you malloc'ed or free something you new'ed. Even then, it might work, except that constructors and destructors won't get called.
Ever since I got malloc working on DevKit Advance it has always malloc'ed out of -External- WRAM. R5 does allow you to malloc out of iwram by defining __gba_iwram_heap, but ewram is the default.
The original poster is being way too vague, and he will not get any help unless he tells us what compiler he is using, enough code to know what he is doing, and the command line he is using to compile.
_________________
http://devkitadv.sourceforge.net
#6882 - tangl_99 - Wed Jun 04, 2003 4:23 am
1.
My complier is the Nintendo Official Compiler.
It consis of a Cygnus and a Armelf-000512.
2.
And the linker didn't report errors!
3.
The makefile is this:
.SFILES = crt0.s
.CFILES = main.c share.c title.c libsound.c
.OFILES = $(.SFILES:.s=.o) $(.CFILES:.c=.o)
AGBINC = $(AGBDIR)/include
AGBLIB = $(AGBDIR)/lib
ASFLAGS = -I$(AGBINC) -mthumb-interwork
CFLAGS = -g -O0 -I$(AGBINC) -mthumb-interwork \
-nostdlib #-DNDEBUG
LDFLAGS += -Map $(MAPFILE) -nostartfiles \
-Ttext 0x08000000 -Tbss 0x03000000 \
-L$(AGBLIB) -lm -lagbsyscall -lisagbprn
DEPENDFILE = Makedepend
MAPFILE = game.map
TARGET_ELF = game.elf
TARGET_BIN = gamegcc.bin
$(TARGET_BIN): $(TARGET_ELF)
objcopy -v -O binary $< $@
$(TARGET_ELF): $(.OFILES) Makefile $(DEPENDFILE)
@echo > $(MAPFILE)
$(CC) -g -o $@ $(.OFILES) -Wl,$(LDFLAGS)
.PHONY: all clean depend
all: clean depend $(TARGET_BIN)
clean:
-rm $(.OFILES) $(DEPENDFILE) $(MAPFILE) $(TARGET_ELF) $(TARGET_BIN)
depend:
$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)
$(DEPENDFILE):
$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)
include Gasdepend
include $(DEPENDFILE)
4.
for example:
u16 *pMem;
pMem=malloc(100);
But in fact the value of pMem is 0.
#6889 - Quirky - Wed Jun 04, 2003 7:40 am
tangl_99 wrote: |
The makefile is this:
AGBINC = $(AGBDIR)/include
AGBLIB = $(AGBDIR)/lib
CFLAGS = -g -O0 -I$(AGBINC) -mthumb-interwork \
-nostdlib #-DNDEBUG
LDFLAGS += -Map $(MAPFILE) -nostartfiles \
-Ttext 0x08000000 -Tbss 0x03000000 \
-L$(AGBLIB) -lm -lagbsyscall -lisagbprn
|
OK, it looks to me like you aren't using the standard malloc in newlib, as you ditch the standard library and use libagbsyscall.a and libisagbprn.a which (I imagine) have some stubs or something to get round complaints about "undefined reference to malloc" without actually implementing it.
That would be my guess anyway.
#6897 - torne - Wed Jun 04, 2003 10:42 am
He's using the real Nintendo development kit (illegal unless he has a licence from Nintendo) which has totally different libraries that don't even pretend to be compatible with libc and friends. =)
Nobody here is likely to help you, I'm afraid; most people haven't used the Nintendo devkit and those who have are likely to keep quiet about it. *grin*
I suggest you throw it away, and get Jason Wilkins' excellent DevKitAdvance instead, because if you release homebrew software with Nintendo libraries linked into it, their lawyers will be paying you a visit.
Torne
#6913 - Jason Wilkins - Wed Jun 04, 2003 2:37 pm
I find it really odd that Nintendo's libraries would have stubs for malloc which do nothing. It would be better to just have the 'undefined symbol' errors.
_________________
http://devkitadv.sourceforge.net
#6916 - niltsair - Wed Jun 04, 2003 3:00 pm
Unless they want to sniff out people without the proper licence, asking questions about it. ;-)
#6924 - Quirky - Wed Jun 04, 2003 4:00 pm
I was just guessing, it might not be that. The closest I've got to an official Nintendo library was buying Wario Ware the other week ;-) It might be that without a decent link script __eheap_start is not defined, so malloc doesn't know where to allocate memory from and just returns 0.
Because Devkit Advance is so great and easy to use (JW's contribution to the GBA community cannot be understated), all this worked first time for me and I haven't really thought about it much :-)
#6929 - torne - Wed Jun 04, 2003 5:44 pm
He is including the embedded version of the Red Hat GNUPro Toolkit C library, and I am pretty sure you need to do some amount of nontrivial setup to let it know where the heap base and limit are before you can call malloc. I don't remember the exact details. I don't have GNUPro installed and can't be bothered to do so to help someone who's using stolen tools and libraries, to be honest.
Throw the Nintendo dev kit away, it blows anyway, and use Jason's excellent DevKitAdvance, with better C library support *grin*
Torne
#6956 - tangl_99 - Thu Jun 05, 2003 6:27 am
Thanks for Torne's note.
The Nintendo's library is worth to study,but I won't release a game by it.It has the offical documents about the GBA.
I have used DevKitAdv for a long time.
But there is some other problems:
How can I use interrupts in DevKitAdv ?
should I download the crt0.s with DevKitAdv?
I don't know how to use it.How to link it?
#6957 - Jason Wilkins - Thu Jun 05, 2003 6:35 am
Of course you can use interrupts.
Rip the interrupt code out of Nintendo's examples or Jeff's crt0.s. They are the same code. Adapt it for your own project. There is not need for the interrupt code to be in crt0.s.
Tommorow, I think I will do this myself and post in on the DKA website, because it is something I mean to include in beta 4, but you are the second person to ask about this.
_________________
http://devkitadv.sourceforge.net