Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
ddgFFco
Posts: 11 Joined: Tue Sep 20, 2005 5:35 pm
Post
by ddgFFco » Thu Sep 29, 2005 3:07 pm
Hey, I can’t seam to get this to work properly. Consider the following code (striped down, but complete):
main.cpp
Code: Select all
#include <pspkernel.h>
extern "C" {
PSP_MODULE_INFO("Test", 0, 1, 1);
class TestClass {
public:
TestClass(int h, int w);
~TestClass();
private:
int** testArray;
int height;
int width;
};
TestClass::TestClass(int h, int w):height(h), width(w) {
testArray = new int*[h];
for (int x = 0; x<h ;x++) {
testArray[x] = new int[w];
}
}
TestClass::~TestClass() {
for (int x = 0; x<height ;x++) {
delete [] testArray[x];
}
delete [] testArray;
}
int main(void) {
TestClass tC(10,10);
sceKernelExitGame();
return 0;
}
}
Makefile:
Code: Select all
TARGET = main
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
When I try to compile I get “undefined reference to ‘operator new[](unsigned int)’” and “undefined reference to ‘operator delete[](void*)’” errors. I’ve updated PSPSDK and still get the errors, is there something I’m doing wrong or a way around this?
Thanks.
CyberBill
Posts: 86 Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA
Post
by CyberBill » Thu Sep 29, 2005 4:57 pm
new and delete are not valid C operators. They only work in C++. Be sure your file is named .cpp, and not .c.
ddgFFco
Posts: 11 Joined: Tue Sep 20, 2005 5:35 pm
Post
by ddgFFco » Thu Sep 29, 2005 5:29 pm
CyberBill wrote:
new and delete are not valid C operators. They only work in C++. Be sure your file is named .cpp, and not .c.
It is named .cpp. PSPSDK seams to require “extern "C" { … }“ for C++. Tried removing it with no luck either.
chp
Posts: 313 Joined: Wed Jun 23, 2004 7:16 am
Post
by chp » Thu Sep 29, 2005 5:54 pm
PSPSDK uses psp-gcc to link with, which does not include certain C++ libraries that contains the new/delete operators. Add -lstdc++ to your libraries that you link with, or roll your own, it's not that hard:
Code: Select all
void* operator new(size_t s)
{
return malloc(s);
}
void operator delete(void* p)
{
free(s);
}
void* operator new[](size_t s)
{
return malloc(s);
}
void operator delete[](void* p)
{
free(s);
}
This thread can be a good reference:
http://forums.ps2dev.org/viewtopic.php?t=561
GE Dominator
ddgFFco
Posts: 11 Joined: Tue Sep 20, 2005 5:35 pm
Post
by ddgFFco » Thu Sep 29, 2005 6:00 pm
Done and working, thanks.