 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
webjeff
Joined: 05 May 2005 Posts: 66
|
Posted: Fri Aug 26, 2005 8:24 am Post subject: C++ not working well |
|
|
OK,
After many tests, It seems C++ is not being initialized properly or something is seriously wrong. Doing the exact same stuff in C works perfect, but in C++ has many errors and crashes on the PSP. Can someone please help and maybe we can get C++ working well on this.
Has anyone really tested C++ working on this platform, not just C?
Thanks
Jeff. |
|
| Back to top |
|
 |
webjeff
Joined: 05 May 2005 Posts: 66
|
Posted: Fri Aug 26, 2005 8:47 am Post subject: |
|
|
Here's the code I used:
| Code: |
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2005 Jesper Svennevid
*/
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
PSP_MODULE_INFO("Lights Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
int SetupCallbacks();
static unsigned int __attribute__((aligned(16))) list[262144];
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4) /* change this if you change to another screenmode */
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */
volatile int g_exit=0;
class TestLogger
{
public:
TestLogger() { };
~TestLogger() { };
void Log() {FILE *file,*file2;
file = fopen("ms0:/PSP/GAME/logtest.txt", "wb");
file2 = fopen("ms0:/PSP/GAME/logtest2.txt", "wb");
fwrite("test data\n", 1, 10, file);
fwrite("test data\n", 1, 10, file2);
fclose(file);
fclose(file2);
};
};
int main(int argc, char* argv[])
{
FILE *file;
FILE *file2;
SetupCallbacks();
sceKernelDcacheWritebackAll();
pspDebugScreenInit();
//sceGuStart(GU_DIRECT,list);
//sceGuInit();
pspDebugScreenPrintf("init logger\n");
//logger.Log();
//g_logger.Init("ms0:/PSP/GAME/log.txt");
//pspDebugScreenPrintf("init content\n");
//g_ContentManager.Init("ms0:/PSP/GAME");
//g_logger.Log(Logger::LL_INFO,"TEST","TEST ");
//g_logger.SetLog( NULL);
pspDebugScreenPrintf("write test file\n");
file = fopen("ms0:/PSP/GAME/logtest.txt", "wb");
file2 = fopen("ms0:/PSP/GAME/logtest2.txt", "wb");
fwrite("test data\n", 1, 10, file);
fwrite("test data\n", 1, 10, file2);
fclose(file);
fclose(file2);
while (g_exit==0)
{
/*sceGuStart(GU_DIRECT,list);
sceGuClearColor(0x554433);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();*/
}
//sceGuTerm();
sceKernelExitGame();
return 0;
}
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
//sceKernelExitGame();
g_exit=1;
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
|
When we call the functions for reading the file directly in C it works fine. As soon as we start to make a class and compile using the stdc++ lib we crash. We also are seeing some weird stuff with C++ in general. I was hoping someone can test or get working a C++ example, I think it would help out our community very nicely, not just me :)
Thanks again guys,
Jeff. |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Fri Aug 26, 2005 9:38 am Post subject: |
|
|
Ever try adding 'extern C' to C++ code? _________________ Lego of my Ago! |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Fri Aug 26, 2005 9:41 am Post subject: |
|
|
| Agoln wrote: | | Ever try adding 'extern C' to C++ code? |
Er, what? |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Fri Aug 26, 2005 9:45 am Post subject: |
|
|
| webjeff wrote: | | When we call the functions for reading the file directly in C it works fine. As soon as we start to make a class and compile using the stdc++ lib we crash. We also are seeing some weird stuff with C++ in general. |
Where does it crash? What type of exception is it? What function does it crash in (psp-objdump -d or psp-addr2line can be of great help here)? Can you provide a slimmed-down piece of code that causes the crash (the code you posted doesn't look complete enough for someone else to repro it)?
No one has reported any strangeness using C++, but it's possible there's something going on in the tools. We need a better idea of what's happening though :). |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Fri Aug 26, 2005 1:09 pm Post subject: |
|
|
I've had many problems with C++ in the past.
First Step, make sure you have the lastest toolchain.
Second Step, modify the Make file. Add these lines
USE_PSPSDK_LIBC = 1
CFLAGS = -O2 -G0 -Wall
Should work fine.
Also, if you still have problems add
extern "C" {
//Code
};
here example of Makefile
| Code: |
TARGET = copy
OBJS = copy.o
INCDIR =
CFLAGS = -02 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
USE_PSPSDK_LIBC = 1
LIBDIR =
LDFLAGS =
LIBS= -lpspgum -lpspgu -lm
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = CopyImage Sample
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
To test this out, try running the sdk/gu/copy/ app. modify the Makefile. and add a basic class in the copy.cpp file.
| Code: |
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <pspgu.h>
#ifndef __cplusplus
extern "C"
{
#endif
PSP_MODULE_INFO("CopyImage Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
class test
{
public:
void hey();
};
void test::hey() { }
....
....
....
int main(int argc, char**argv)
{
test *t=new test;
t->hey();
...
}
...
....
#ifndef __cplusplus
}; //end extern "C"
#endif
|
heres a example of code that is writting in C++ for the PSP, compiles fine, and works fine on the psp
http://tmpstore.free.fr/FileAssistant/viewtopic.php?t=21
edit:
I've also tried this with the Light project, works perfectly fine. let me know if you have any problems. _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| Back to top |
|
 |
Krevnik
Joined: 09 Mar 2005 Posts: 71
|
Posted: Fri Aug 26, 2005 11:29 pm Post subject: |
|
|
| You could probably just wrap the main function in the extern C, IIRC as well. |
|
| Back to top |
|
 |
|
|
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
|