"New" operator is undefined

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

Moderators: cheriff, TyRaNiD

Post Reply
JustChris
Posts: 21
Joined: Thu Nov 03, 2005 7:17 am

"New" operator is undefined

Post by JustChris »

I can't seem to use much of STL because most of them use the 'new' and 'delete' operators. In fact, just dynamically allocating objects gives me the error.

Code: Select all

int *ptr;
ptr = new int[10];

// error returned
main.cpp:(.text+0x5a30): Undefined reference to 'operator new[](unsigned int)'

Is there something that I forgot to link against? Here is the makefile used.

Code: Select all

TARGET = Test
OBJS = main.o sprite.o psp-setup.o sprite-rgba.o map1-rgba.o sprite-mono.o

INCDIR =
CFLAGS = -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =
LIBS = -lglut -lGL -lm -lpsprtc

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Testing
PSP_EBOOT_ICON = test.png

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

AS=psp-as

psp-setup.o: psp-setup.c Makefile
psp-setup.o: CFLAGS += -DMODULE_NAME="$(TARGET)"

sprite.o: sprite.cpp sprite.h
main.o: main.cpp sprite.h

%.o: %.raw
	(sym=`echo $* | tr '-' '_'`; \
	 echo -e ".data\n.global $$&#123;sym&#125;_start\n$$&#123;sym&#125;_start&#58;\n\t.incbin \"$<\"" | $&#40;AS&#41; -o $@&#41;

%-rgba.raw&#58; %-rgba.png
	convert $< rgba&#58;$@

%-mono.raw&#58; %-mono.png
	convert $< gray&#58;$@

%-sys.o&#58; %.c
	gcc -g -Wall -DSYS -c -o $@ $<

sys&#58; test-sys.o sprite-sys.o sprite-mono.o sprite-rgba.o
	gcc -o sys $^ -lglut
EDIT: NVM, it got fixed! I didn't add -lstdc++ to LIBS.
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

Link with stdc++

-lstdc++ to your LIBS variable in your makefile. That should do it.
Br, Sandberg
Post Reply