forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Leviathan2040



Joined: 09 Jul 2005
Posts: 7

PostPosted: Sat Jul 09, 2005 5:44 pm    Post subject: On C++ with PSPSDK... again... Reply with quote

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:

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
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Sun Jul 10, 2005 1:45 am    Post subject: Reply with quote

Please post the errors. We're not mind readers.
Back to top
View user's profile Send private message Visit poster's website
Zeta



Joined: 09 Jul 2005
Posts: 9

PostPosted: Sun Jul 10, 2005 2:02 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Leviathan2040



Joined: 09 Jul 2005
Posts: 7

PostPosted: Sun Jul 10, 2005 10:58 am    Post subject: Reply with quote

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

Code:

/*
 * 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 (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
 * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
 * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
 *
 * $Id: main.c 363 2005-06-27 20:35:14Z tyranid $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>

class TestClass {
public:
   int m_K;
};


/* Define the module info section */
PSP_MODULE_INFO("SDKTEST", 0, 1, 1);

/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

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

extern "C" {

void dump_threadstatus(void);

/* Exit callback */
int exit_callback(void)
{
   sceKernelExitGame();

   return 0;
}

/* Callback thread */
void CallbackThread(void *arg)
{
   int cbid;

   printf("\nCallback Thread Status:\n");
   dump_threadstatus();
   cbid = sceKernelCreateCallback("Exit Callback", (void*)exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);

   sceKernelSleepThreadCB();
}

/* Dump the current thread's status */
void dump_threadstatus(void)
{
   int thid;
   ThreadStatus status;
   int ret;

   thid = sceKernelGetThreadId();
   memset(&status, 0, sizeof(ThreadStatus));
   printf("Thread ID: %08X\n", thid);
   status.size = sizeof(ThreadStatus);
   ret = sceKernelReferThreadStatus(thid, &status);
   printf("Get Thread Status: %08X\n", ret);
   if(ret == 0)
   {
      printf("Name: %s\n", status.name);
      printf("Thread Addr: %08X\n", status.th_addr);
      printf("Stack Addr: %08X\n", status.stack_addr);
      printf("Stack Size: %08X\n", status.stack_size);
      printf("gp: %08X\n", status.gp);
      printf("Initial Pri: %x\n", status.init_pri);
      printf("Current Pri: %x\n", status.curr_pri);
   }
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", (void*)CallbackThread, 0x11, 0xFA0, 0, 0);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}

int main(void)
{
   pspDebugScreenInit();
   printf("Bootpath: %s\n", g_elf_name);
   SetupCallbacks();
   printf("\nMain Thread Status:\n");
   dump_threadstatus();


   TestClass* TestObj = new TestClass;

   TestObj->m_K = 1234;

   delete TestObj;


   sceKernelSleepThread();

   return 0;
}
}






This is the makefile:


Code:

TARGET = test
OBJS = test.o

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

LIBDIR =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test v1.0

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



also I've modified the build.mak from:

Code:

PSPSDK_LIBC_LIB = -lpsplibc


to

Code:

PSPSDK_LIBC_LIB = -lpsplibc -lpspglue


when I tried to execute the makefile, this is what I get:

Quote:


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
Back to top
View user's profile Send private message
mc



Joined: 12 Jan 2005
Posts: 212
Location: Linköping

PostPosted: Sun Jul 10, 2005 9:20 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group