| View previous topic :: View next topic |
| Author |
Message |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Mon Sep 10, 2007 9:37 am Post subject: Problems with sdl and c++ |
|
|
Hello actually i'm developing a game for psp in c++ and SDL. In order to speed up the debuging i maked all the game engine in the pc using only sdl standards and C++ STD.
But now i want to try the code in the psp in order to make a checkpoint. But i tried a easy hello word in psp sdl c++ but it doesnt work it says something like:
SDL_main not defined
at linking. But compiling a game with sdl and c ( not C++) it works pretty good.
What do you think i can do to solve the problem? |
|
| Back to top |
|
 |
AllSystemGo
Joined: 02 Jun 2007 Posts: 26
|
Posted: Mon Sep 10, 2007 10:24 am Post subject: |
|
|
| Are you sure you installed the SDL??? |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Mon Sep 10, 2007 10:46 am Post subject: |
|
|
As i've said i have already make a c game using sdl ( yes an entire game!) so... yes it is installed.
but the problem only appears when i'm using c++
also if someone has tried sdl on c++ using pspsdk and sdl libraries and can lend me a hand attaching a sample code Something like a hello world and a makefile.
the compiling order is:
| Code: | psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -Wall -Wno-long-long -G0 -O2 -DJOY_YES -I/usr/local/pspdev/psp/include/SDL -Dmain=SDL_main -c -o test1.o test1.cpp
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -Wall -Wno-long-long -G0 -O2 -DJOY_YES -I/usr/local/pspdev/psp/include/SDL -Dmain=SDL_main -c -o csprite.o csprite.cpp
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -Wall -Wno-long-long -G0 -O2 -DJOY_YES -I/usr/local/pspdev/psp/include/SDL -Dmain=SDL_main -D_PSP_FW_VERSION=150 -L. -L/usr/local/pspdev/psp/sdk/lib test1.o csprite.o -L/usr/local/pspdev/psp/lib -lSDLmain -lSDL -lm -lGL -lpspvfpu -L/usr/local/pspdev/psp/sdk/lib -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o testi.elf
|
notice that it links using gcc so i think there is a problem too thats why i tried using the same order but using psp-g++ to avoid the operator new[](unsigned int)' not defined error.
the entire error log is:
| Code: |
/usr/local/pspdev/psp/lib/libSDLmain.a(SDL_psp_main.o): En la función `sdl_psp_exit_callback':
psp/SDL_psp_main.c:54: definiciones múltiples de `sce_newlib_attribute'
test1.o:(.data+0x0): primero se definió aquí
/usr/local/pspdev/psp/lib/libSDLmain.a(SDL_psp_main.o): En la función `sdl_psp_exit_callback':
psp/SDL_psp_main.c:54: definiciones múltiples de `module_info'
test1.o:(.rodata.sceModuleInfo+0x0): primero se definió aquí
test1.o:(.eh_frame+0x11): referencia a `__gxx_personality_v0' sin definir
csprite.o: En la función `CSprite::CSprite(int)':
csprite.cpp:(.text+0x9c): referencia a `operator new[](unsigned int)' sin definir
csprite.o: En la función `CSprite::CSprite(int)':
csprite.cpp:(.text+0xdc): referencia a `operator new[](unsigned int)' sin definir
csprite.o: En la función `CSprite::CSprite()':
csprite.cpp:(.text+0x114): referencia a `operator new[](unsigned int)' sin definir
csprite.o: En la función `CSprite::CSprite()':
csprite.cpp:(.text+0x14c): referencia a `operator new[](unsigned int)' sin definir
csprite.o:(.eh_frame+0x11): referencia a `__gxx_personality_v0' sin definir
/usr/local/pspdev/psp/lib/libSDLmain.a(SDL_psp_main.o): En la función `main':
psp/SDL_psp_main.c:(.text+0x358): referencia a `SDL_main' sin definir
collect2: ld devolvi'o el estado de salida 1
make: *** [testi.elf] Error 1
|
EDIT:--------------------------------------------------------------------------------------------------
in order to compile i've tried this commands:
| Code: | psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -Wall -Wno-long-long -G0 -O2 -DJOY_YES -I/usr/local/pspdev/psp/include/SDL -c -o test1.o test1.cpp
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -Wall -Wno-long-long -G0 -O2 -DJOY_YES -I/usr/local/pspdev/psp/include/SDL -c -o csprite.o csprite.cpp
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -Wall -Wno-long-long -G0 -O2 -DJOY_YES -I/usr/local/pspdev/psp/include/SDL -D_PSP_FW_VERSION=150 -L. -L/usr/local/pspdev/psp/sdk/lib test1.o csprite.o -L/usr/local/pspdev/psp/lib -lSDLmain -lSDL -lm -lGL -lpspvfpu -L/usr/local/pspdev/psp/sdk/lib -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o testi.elf
|
it now compiles without errors but the game doesn't run on psp so i'm thinking that it should be problem that the main is not defined in the elf the app doesn't know where to start. could it be??
Last edited by saulotmalo2 on Mon Sep 10, 2007 10:54 am; edited 1 time in total |
|
| Back to top |
|
 |
AllSystemGo
Joined: 02 Jun 2007 Posts: 26
|
Posted: Mon Sep 10, 2007 10:49 am Post subject: |
|
|
Did you add the SDL in your Makefile??
I'm new to this psp deving too, I'm just trying to help.
BTW I'm using the SDL in my project!! |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Mon Sep 10, 2007 10:56 am Post subject: |
|
|
its ok, all the helps are welcome. Also i'm not new ... but i've forgot the password xD. And i have develop some psp apps. But now it is turning me mad.
your project uses C++ & sdl? can i have your makefile or your... source? i mean only a litle hello world would be perfect.
EDIT: as you can see on the post before i'm linking the main and the sdl but i'm not sure about what -Dmain is doing so i've erased it but... now it compiles but don't run :( |
|
| Back to top |
|
 |
AllSystemGo
Joined: 02 Jun 2007 Posts: 26
|
Posted: Mon Sep 10, 2007 11:05 am Post subject: |
|
|
Here is my Makefile
| Code: |
TARGET = Test
OBJS = main.o $(PSP_OBJS)
INCDIR =
CFLAGS = -G4 -Wall -O3 -I/usr/local/pspdev/psp/include/SDL
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
PSPSDK=$(shell psp-config --pspsdk-path)
PSPBIN = $(PSPSDK)/../bin
LIBDIR =
LDFLAGS =
STDLIBS= -lSDLmain -lSDL_image -lSDL_ttf -lfreetype -lSDL -lpng -ljpeg -lm -lz -lstdc++ \
-lpspsdk -lpspctrl -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lpsphprm \
-lSDL_mixer -lpsphprm
LIBS=$(STDLIBS)$(YOURLIBS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test
PSPSDK=$(shell psp-config --pspsdk-path)
DEFAULT_CFLAGS = $(shell $(SDL_CONFIG) --cflags)
include $(PSPSDK)/lib/build.mak
|
and a bit of my Main.cpp
| Code: |
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <psppower.h>
#include <psprtc.h>
#include <png.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string>
#include <list>
#include <iostream>
#include <fstream>
#include "alarm.h"
#include "alarmmanager.h"
#include "button.h"
using namespace std;
PSP_MODULE_INFO("Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
static bool isrunning = true;
static int curWindow = 1;
// Exit callback
int exit_callback(int arg1, int arg2, void *common) {
isrunning = false;
sceKernelExitGame();
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;
}
int main() {
//Initialize the controler and the PSP Speed
SceCtrlData pad;
scePowerSetClockFrequency(166, 166, 166);
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
//Initialize the SDL Library (audio and video)
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
cout << stderr << "Couldn't initialize SDL: " << SDL_GetError() << endl;
//Initialize the SDL True Type Font Library
if(TTF_Init() < 0)
cout << stderr << "Couldn't initialize TTF: " << SDL_GetError() << endl;
//Initialize the font color.
SDL_Color white = {255, 255, 255};
SDL_Color black = {0, 0, 0};
//Initializing the images and text.
/*SDL_Rect txtcalendar_position;
txtcalendar_position.x = 130;
txtcalendar_position.y = 146;*/
//Chargement des images.
SDL_Surface *background;
SDL_Surface *ecran = SDL_SetVideoMode(480, 272, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
background = SDL_DisplayFormat(IMG_Load("data/gfx/blackbackground.png"));
//iconCalendar = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/calendar.png"));
//Initialisation du mode Debug de la PSP
pspDebugScreenInit();
SetupCallbacks();
//Start the loop
while(isrunning)
{
sceCtrlReadBufferPositive(&pad, 1);
sceRtcGetCurrentClockLocalTime(&time);
SDL_BlitSurface(background, NULL, ecran, &background_position);
SDL_BlitSurface(mousePointer, NULL, ecran, &mouse);
SDL_Flip(ecran);
}
//Free the memory.
SDL_FreeSurface(background);
SDL_Quit();
sceKernelSleepThread();
return 0;
}
|
I understand it's a quick example.. Let me know if you anything else
Cheers |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Mon Sep 10, 2007 11:13 am Post subject: |
|
|
| Also, in AllSystemGo's makefile, he included this library called: libstd++. You'll need it in your makefile to use C++ at all in your projects. I think adding that in will fix it. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Mon Sep 10, 2007 11:32 am Post subject: |
|
|
when i compile your code i get this errors:
| Code: | /usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(eglCreateContext.o): En la función `eglCreateContext':
/cygdrive/c/pspgl2/eglCreateContext.c:43: referencia a `pspvfpu_initcontext' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(eglDestroyContext.o): En la función `eglDestroyContext':
/cygdrive/c/pspgl2/eglDestroyContext.c:42: referencia a `pspvfpu_deletecontext' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(glLoadIdentity.o): En la función `glLoadIdentity':
/cygdrive/c/pspgl2/glLoadIdentity.c:23: referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(pspgl_context.o): En la función `flush_matrix':
/cygdrive/c/pspgl2/pspgl_context.c:107: referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(pspgl_matrix.o): En la función `__pspgl_matrix_sync':
/cygdrive/c/pspgl2/pspgl_matrix.c:19: referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(pspgl_matrix.o): En la función `__pspgl_matrix_load':
/cygdrive/c/pspgl2/pspgl_matrix.c:33: referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a(glMultMatrixf.o): En la función `glMultMatrixf':
/cygdrive/c/pspgl2/glMultMatrixf.c:17: referencia a `pspvfpu_use_matrices' sin definir
collect2: ld devolvi'o el estado de salida 1
make: *** [Test.elf] Error 1
|
i tried to clean a little but i don't know where is the problem :(
EDIT-----------------------------------------------------------------------------------------
can you put the code that the makefile tries to compile? because a leak some libraries that you have.
only put on the shell :
make > log.txt
and send the log.txt.
thaks i think i'm getting the error |
|
| Back to top |
|
 |
VZsolt
Joined: 10 Sep 2007 Posts: 2
|
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Sep 10, 2007 5:31 pm Post subject: |
|
|
| Put main() in an extern C block. Search the forums for more info; this has been asked lots of times before. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Mon Sep 10, 2007 9:26 pm Post subject: |
|
|
i have compiled using AllSystemGo schema now it works ( at least i can compile c++ sdl on psp) but i like to use sdlmain standard, that means that i don't have to redefine the callbacks.
how can i do it?
EDIT--------------------------------------------------------------------------------
i've tried use extern but then when i trie to execute the game frezes. ( even does not start) |
|
| Back to top |
|
 |
VZsolt
Joined: 10 Sep 2007 Posts: 2
|
Posted: Tue Sep 11, 2007 4:36 am Post subject: |
|
|
| IIRC the README.PSP file in SDL has a paragraph about this. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Tue Sep 11, 2007 6:28 am Post subject: |
|
|
| yes i've read about it but it doesn't say how can i use the sdl_main i think it could be because the mangling of the sdl_main.c |
|
| Back to top |
|
 |
|