#9126 - abonetochew - Mon Jul 28, 2003 9:29 pm
I have installed DevKitAdv and it works almost perfectly for me. This new program I'm working on uses (or tries to) the c++ new and delete operators. I think I have the syntax correct, because I don't get any error messages right away, but when it's almost done compiling I get an error message like this:
/windows/TEMP/ccmlRafJ.o: In function `unit::walkto(int, int)':
/windows/TEMP/ccmlRafJ.o(.text+0x34): undefined reference to `operator delete(void*)'
/windows/TEMP/ccmlRafJ.o(.text+0x3c): undefined reference to `operator new[](unsigned long)'
/windows/TEMP/ccmlRafJ.o: In function `unit::doit(int, int, int)':
/windows/TEMP/ccmlRafJ.o(.text+0x3b4): undefined reference to `operator delete[](void*)'
/windows/TEMP/ccmlRafJ.o(.text+0x5e0): undefined reference to `operator delete[](void*)'
/windows/TEMP/ccmlRafJ.o(.text+0x648): undefined reference to `operator delete[](void*)'
collect2: ld returned 1 exit status
The "ccmlRafJ.o" part changes each time I try. Did I forget something obvious?
_________________
DS... shiny...
#9132 - yaustar - Tue Jul 29, 2003 12:29 am
Post the code so we can see what we are working with...
_________________
[Blog] [Portfolio]
#9133 - hnager - Tue Jul 29, 2003 12:37 am
What are you compiling with? gcc or g++?
#9134 - abonetochew - Tue Jul 29, 2003 1:47 am
Here's my code (gcc). Don't worry if it's suboptimal, won't work, or is just plain stupid. I just want it to compile so I can debug it. I have written about 50% of that since I added new and delete, so about half of it is untested.
Code: |
//Include other data
#include "gba.h"
#include "keys.h"
#include "dispcnt.h"
#include "palette.h"
#include "BG0tdata.h"
#include "BG1tdata.h"
#include "BG0mdata.h"
#include "OBJtdata.h"
//Define some pointers
u16* BG0Tiles = (u16*)0x6000000;
u16* BG1Tiles = (u16*)0x6004000;
u16* BG0Map = (u16*)0x6008000;
u16* BG1Map = (u16*)0x6008800;
u16* SpriteTiles = (u16*)0x6010000;
u16* PaletteMemory = (u16*)0x5000000;
u16* SpritePalette = (u16*)0x5000200;
u16* OAM = (u16*)0x7000000;
class unit {
int x;
int y;
int gx;
int gy;
int wx;
int wy;
int maxhp;
int nowhp;
int walking;
u8* path;
int between;
int walkindex;
public:
void walkto(int, int);
void doit(int, int, int);
void createunit(int, int);
};
void unit::walkto(int tx, int ty) {
if(walking == 1)
delete path;
int o,d,xd,yd,nx,ny;
path = new u8[10];
walking = 1;
between = 0;
walkindex = 0;
o = 0;
gx = tx;
gy = ty;
nx = x;
ny = y;
while(o < 10) {
xd = yd = d = 0;
if(tx < nx) {nx--; xd = 1; d = 1;}
if((tx == nx) && (xd = 0)) {xd = 1; d = 2;}
if((tx > nx) && (xd = 0)) {nx++; xd = 1; d = 3;}
if(ty < ny) {ny--; yd = 1; d += 6;}
if((ty == ny) && (yd = 0)) {yd = 1; d += 3;}
if((ty > ny) && (yd = 0)) {ny++; yd = 1;}
path[o] = d;
if(d == 5) {break;}
o++;
}
}
void unit::doit(int oamindex, int vx, int vy) {
int d;
if(walking == 1) {
if(between == 0) {
wx = x / 8;
wy = y / 8;
d = path[walkindex];
switch(d) {
case 1: wx--; wy++; break;
case 2: wy++; break;
case 3: wx++; wy++; break;
case 4: wx--; break;
case 6: wx++; break;
case 7: wx--; wy--; break;
case 8: wy++; break;
case 9: wx++; wy--; break;
}
if(d == 5) {
delete [] path;
walking = 0;
between = 0;
}
else {
wx *= 8;
wy *= 8;
between = 1;
if(x < wx) {x--;}
if(x > wx) {x++;}
if(y < wy) {y--;}
if(y > wy) {y++;}
}
}
else {
if(x < wx) {x--;}
if(x > wx) {x++;}
if(y < wy) {y--;}
if(y > wy) {y++;}
if((x == wx) && (y == wy)) {
walkindex++;
between = 0;
if(walkindex >= 10) {
delete [] path;
walking = 0;
between = 0;
}
}
if((x == gx * 8) && (y == gy * 8)) {
delete [] path;
walking = 0;
between = 0;
}
}
}
if((y - vy > -8) && (y - vy < 168) && (x - vx > -8) && (x - vx < 248)) {
OAM[oamindex] = y - vy | 0x2000;
OAM[oamindex + 1] = x - vx;
OAM[oamindex + 2] = 1;
}
}
void unit::createunit(int nx, int ny) {
x = nx;
y = ny;
maxhp = 10;
nowhp = 10;
walking = 0;
between = 0;
}
u8 obstacles[64][64];
unit bob;
int main() {
//Declare my variables
int o,x,y,sx,sy,gx,gy,vx,vy;
REG_DISPCNT = MODE_1 | OBJ_MAP_1D;
//Load background palette
for(o = 0; o < 256; o++)
PaletteMemory[o] = palette[o];
//Load sprite palettes
for(o = 0; o < 256; o++)
SpritePalette[o] = palette[o];
//Load 256 BG0 tiles (16384 bytes/8192 u16's)
for(o = 0; o < 8192; o++)
BG0Tiles[o] = BG0tiledata[o];
//Load 256 BG1 tiles (16384 bytes/8192 u16's)
for(o = 0; o < 8192; o++)
BG1Tiles[o] = BG1tiledata[o];
//Load 256x256 BG0 map (2048 bytes/1024 u16's)
for(o = 0; o < 1024; o++)
BG0Map[o] = BG0mapdata[o];
//Fill 512x512 BG1 map with 1's (8192 bytes/4096 u16's)
for(o = 0; o < 4096; o++)
BG1Map[o] = 0x0001;
//Load 256 OBJ tiles (16384 bytes/8192 u16's)
for(o = 0; o < 8192; o++)
SpriteTiles[o] = OBJtiledata[o];
REG_BG0CNT = 0x1080;
REG_BG0HOFS = 96;
REG_BG1CNT = 0xD186;
sx = 0;
sy = 0;
BG1Map[0] = 0x0004;
gx = 19;
gy = 19;
BG1Map[627] = 0x0005;
x = 120;
y = 80;
bob.createunit(0,0);
while(!(REG_DISPSTAT & 0x0001)) { //wait for vblank
}
REG_DISPCNT = MODE_1 | OBJ_MAP_1D | BG0_ENABLE | BG1_ENABLE | OBJ_ENABLE;
while(1) { //loop forever
while(!(REG_DISPSTAT & 0x0001)) { //wait for vblank
}
if(REG_P1 & KEY_L) {
if(!(REG_P1 & KEY_LEFT)) {
x -= 4;
if(x < 0)
x = 0;
}
if(!(REG_P1 & KEY_RIGHT)) {
x += 4;
if(x > 239)
x = 239;
}
if(!(REG_P1 & KEY_UP)) {
y -= 4;
if(y < 0)
y = 0;
}
if(!(REG_P1 & KEY_DOWN)) {
y += 4;
if(y > 159)
y = 159;
}
}
if(!(REG_P1 & KEY_L)) {
if(!(REG_P1 & KEY_LEFT)) {
vx -= 4;
if(vx < 0)
vx = 0;
}
if(!(REG_P1 & KEY_RIGHT)) {
vx += 4;
if(vx > 352)
vx = 352;
}
if(!(REG_P1 & KEY_UP)) {
vy -= 4;
if(vy < 0)
vy = 0;
}
if(!(REG_P1 & KEY_DOWN)) {
vy += 4;
if(vy > 352)
vy = 352;
}
}
if(x < 160) {
if(!(REG_P1 & KEY_B)) {
gx = (x + vx) >> 3;
gy = (y + vy) >> 3;
bob.walkto(gx, gy);
}
}
//scroll BG1
REG_BG1HOFS = vx;
REG_BG1VOFS = vy;
//y coord, 256 colors, [16x32]
OAM[0] = (y & 0x00FF) | 0x2000 | 0x8000;
//x coord, [16x32]
OAM[1] = (x & 0x01FF) | 0x8000;
OAM[2] = 2;
OAM[3] = 0;
OAM[4] = 0;
OAM[5] = 0;
OAM[6] = 0;
OAM[7] = 0;
bob.doit(4, vx, vy);
while(REG_DISPSTAT & 0x0001) { //wait for vdraw
}
}
} |
_________________
DS... shiny...
#9135 - hnager - Tue Jul 29, 2003 2:51 am
I had the same problem a while back, did you try compiling with g++?
#9137 - abonetochew - Tue Jul 29, 2003 4:12 am
what is g++?
_________________
DS... shiny...
#9141 - tepples - Tue Jul 29, 2003 6:30 am
g++ is the same as gcc except it links in some extra libraries necessary for C++ language support.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#9157 - abonetochew - Tue Jul 29, 2003 4:03 pm
Well, that would explain it. How do I compile with the g++ libraries?
_________________
DS... shiny...
#9161 - tepples - Tue Jul 29, 2003 4:56 pm
Provided your link script and crt0 support g++ (the ones included with DevKit Advance R4 and R5 beta 3 do), just replace gcc with g++ in your linking command line (the one that produces the .elf).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#9165 - abonetochew - Tue Jul 29, 2003 6:12 pm
No more errors! Thanks everyone!
_________________
DS... shiny...