Closed SeedyROM closed 7 years ago
Which compiler (and version) are you using? Also on what platform?
I'm currently running it under Ubuntu 16.04, 64-bit AMD. Here's my version information for the compilers.
-> % lcc -v
lcc $Id: lcc.c,v 1.6 2001/10/28 18:38:13 michaelh Exp $
-> % sdcc -v
SDCC : gbz80/z80 2.3.1/gbdk-2.96a (Feb 14 2017) (UNIX)
I wrote a test program to showcase what I'm experiencing, maybe I'm just an idiot and I'm missing something huge.
#include <stdio.h> // For debug.
#include <stdlib.h> // Shouldn't malloc be included here?
#include <gb/gb.h>
#include <gb/malloc.h> // Doesn't throw an error finding the header file.
// But nothing gets defined.
// Stupid simple struct.
typedef struct _object {
UBYTE x, y;
BYTE vx, vy;
} object;
void main() {
object *obj = (object *)malloc(sizeof(object)); // Implicit delcaration?
printf("%d", sizeof(obj));
}
If i compile it with lcc -v -c main.c
this is the console output I get:
lcc $Id: lcc.c,v 1.6 2001/10/28 18:38:13 michaelh Exp $
/opt/gbdk/bin/sdcpp -Wall -lang-c++ -DSDCC=1 -DSDCC_PORT=gbz80 -DSDCC_PLAT=gb -DSDCC_MODEL_SMALL -DGB=1 -DGAMEBOY=1 -DINT_16_BITS -D__LCC__ -I/opt/gbdk/include main.c /tmp/lcc45600.i
/opt/gbdk/bin/sdcc -mgbz80 --noinvariant --noinduction --nostdinc --nostdlib --model-small --c1mode /tmp/lcc45600.i /tmp/lcc45601.asm
main.c(15):warning *** function 'malloc' implicit declaration
main.c(15):error *** too many parameters
main.c(15):warning *** function 'malloc' implicit declaration
main.c(16):error *** code not generated for 'main' due to previous errors
lcc: fatal error in /opt/gbdk/bin/sdcc
rm /tmp/lcc45601.asm /tmp/lcc45600.i
Hope that's enough info.
Thanks for the example. Yes it seems that the malloc.h
does not contain the declaration of malloc()
, you might need to use gbdk-lib/libc/malloc.c
.
I am not really familiar with the code but I could not find usage of malloc()
in any of the example codes. In malloc.h
there is a comment saying "Header for a simple implementation of malloc(). This library may currently be broken.".
There is a newer version of gbdk called gbdk-n but the malloc.h
is the same.
Yeah, I realized this after a dig through the source code not long after I sent this issue.
Thank you for getting back in touch though!
Upon compiling all of the memory allocation, etc. functions aren't defined. I'm not entirely sure why, but this is what I get in the console.
Is this just a weird bug on my end?