On C++ with PSPSDK... again...

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

Moderators: cheriff, TyRaNiD

Post Reply
Leviathan2040
Posts: 7
Joined: Sat Jul 09, 2005 5:26 pm

On C++ with PSPSDK... again...

Post by Leviathan2040 »

Hi all,
I've downloaded, installed (several times) the PSP SDK, Cygwin and all related tools. So far I've been able to compile C programs only, I've read several threads about C++ compilation with current version of PSPSDK, but so far I really had no luck in getting bpast the compilation fase.

I just tried to create a simple main.cpp file with a basic class declaration (containing just an integer member), in the main function I only declare an object of the class using the 'new' operator, assign a value to the class member and dispose the object using 'delete'.


file TEST.CPP

Code: Select all

class TestClass {
public:
	int m_K;
};


int xmain(void)
{
	TestClass* TestObj = new TestClass;

	TestObj->m_K = 1234;

	delete TestObj;

	return 0;
}

whenever I try to compile the above code, I only get errors.

Can please somebody write a basic Makefile with the all necessary options to compile it? I've been working with GCC on other embedded systems for years but this one seems to be a bit different from the others toolchain I've used and I can't find any doc. I was hoping that by looking at the SCUMM-VM PSP makefile I was able to solve the problem, but either I can't find the ported project (I know it is still under porting fase) nor there is an indication on what they had to change.


Thanx in advance.


Cheers,
Lev
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Please post the errors. We're not mind readers.
Zeta
Posts: 9
Joined: Sat Jul 09, 2005 1:46 pm

Post by Zeta »

I've been able to compile your example with a simple makefile as this

PSPSDK = $(shell psp-config --pspsdk-path)
PSPLIBSDIR = $(PSPSDK)/..
TARGET = test
OBJS = main.o
LIBS =


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

include $(PSPSDK)/lib/build.mak
Leviathan2040
Posts: 7
Joined: Sat Jul 09, 2005 5:26 pm

Post by Leviathan2040 »

Sorry for the incomplete question, this is the TEST.CPP file I've used:

Code: Select all

/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Basic PSPSDK sample.
 *
 * Copyright &#40;c&#41; 2005 Marcus R. Brown <mrbrown@ocgnet.org>
 * Copyright &#40;c&#41; 2005 James Forshaw <tyranid@gmail.com>
 * Copyright &#40;c&#41; 2005 John Kelley <ps2dev@kelley.ca>
 *
 * $Id&#58; main.c 363 2005-06-27 20&#58;35&#58;14Z tyranid $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>

class TestClass &#123; 
public&#58; 
   int m_K; 
&#125;; 


/* Define the module info section */
PSP_MODULE_INFO&#40;"SDKTEST", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

/* Define printf, just to make typing easier */
#define printf	pspDebugScreenPrintf

extern "C" &#123;

void dump_threadstatus&#40;void&#41;;

/* Exit callback */
int exit_callback&#40;void&#41;
&#123;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
void CallbackThread&#40;void *arg&#41;
&#123;
	int cbid;

	printf&#40;"\nCallback Thread Status&#58;\n"&#41;;
	dump_threadstatus&#40;&#41;;
	cbid = sceKernelCreateCallback&#40;"Exit Callback", &#40;void*&#41;exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;
&#125;

/* Dump the current thread's status */
void dump_threadstatus&#40;void&#41;
&#123;
	int thid;
	ThreadStatus status;
	int ret;

	thid = sceKernelGetThreadId&#40;&#41;;
	memset&#40;&status, 0, sizeof&#40;ThreadStatus&#41;&#41;;
	printf&#40;"Thread ID&#58; %08X\n", thid&#41;;
	status.size = sizeof&#40;ThreadStatus&#41;;
	ret = sceKernelReferThreadStatus&#40;thid, &status&#41;; 
	printf&#40;"Get Thread Status&#58; %08X\n", ret&#41;;
	if&#40;ret == 0&#41;
	&#123;
		printf&#40;"Name&#58; %s\n", status.name&#41;;
		printf&#40;"Thread Addr&#58; %08X\n", status.th_addr&#41;;
		printf&#40;"Stack Addr&#58; %08X\n", status.stack_addr&#41;;
		printf&#40;"Stack Size&#58; %08X\n", status.stack_size&#41;;
		printf&#40;"gp&#58; %08X\n", status.gp&#41;;
		printf&#40;"Initial Pri&#58; %x\n", status.init_pri&#41;;
		printf&#40;"Current Pri&#58; %x\n", status.curr_pri&#41;;
	&#125;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", &#40;void*&#41;CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

int main&#40;void&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	printf&#40;"Bootpath&#58; %s\n", g_elf_name&#41;;
	SetupCallbacks&#40;&#41;;
	printf&#40;"\nMain Thread Status&#58;\n"&#41;;
	dump_threadstatus&#40;&#41;;


	TestClass* TestObj = new TestClass; 

	TestObj->m_K = 1234; 

	delete TestObj; 


	sceKernelSleepThread&#40;&#41;;

	return 0;
&#125;
&#125;




This is the makefile:

Code: Select all

TARGET = test
OBJS = test.o

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test v1.0

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

also I've modified the build.mak from:

Code: Select all

PSPSDK_LIBC_LIB = -lpsplibc
to

Code: Select all

PSPSDK_LIBC_LIB = -lpsplibc -lpspglue
when I tried to execute the makefile, this is what I get:

psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/pspdev/psp/sdk/lib test.o -lpspdebug -lpsplibc -lpspglue -lpspkernel -o test.elf
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/crt0.o: In function `__entrytable':
crt0.S:(.rodata.sceResident+0xc): undefined reference to `module_info'
test.o: In function `main':
test.cpp:(.text+0x1fc): undefined reference to `operator new(unsigned int)'
test.cpp:(.text+0x20c): undefined reference to `operator delete(void*)'
collect2: ld returned 1 exit status
make: *** [test.elf] Error 1

I've read already the threads about problems in using the new and delete operators, tried several combinations of LIBS but so far no luck


Cheers,
Lev
User avatar
mc
Posts: 211
Joined: Wed Jan 12, 2005 7:32 am
Location: Linköping

Post by mc »

Seems to compile fine with an SDK fresh from SVN. Although you have to replace the dump_threadstatus() function with a more up-to-date one, some names have changed in the thread API.

So I guess the solution to your problem is: upgrade. :-)
Flying at a high speed
Having the courage
Getting over crisis
I rescue the people
Post Reply