Problems with sdl and c++

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

Moderators: cheriff, TyRaNiD

Post Reply
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Problems with sdl and c++

Post by saulotmalo2 »

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?
AllSystemGo
Posts: 26
Joined: Sat Jun 02, 2007 1:15 am

Post by AllSystemGo »

Are you sure you installed the SDL???
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

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: Select all

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: Select all


/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: Select all

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.
AllSystemGo
Posts: 26
Joined: Sat Jun 02, 2007 1:15 am

Post by AllSystemGo »

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!!
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

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 :(
AllSystemGo
Posts: 26
Joined: Sat Jun 02, 2007 1:15 am

Post by AllSystemGo »

Here is my Makefile

Code: Select all

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: Select all


#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&#40;"Test", 0, 1, 1&#41;;

PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;



static bool isrunning = true;

static int curWindow = 1;



// Exit callback

int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;

	isrunning = false;

	sceKernelExitGame&#40;&#41;;

	return 0;

&#125;



// Callback thread 

int CallbackThread&#40;SceSize args, void *argp&#41; &#123;

	int cbid; 

	

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;

	sceKernelRegisterExitCallback&#40;cbid&#41;;

	

	sceKernelSleepThreadCB&#40;&#41;;

 	

	return 0;

&#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", 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;&#41; &#123;

	//Initialize the controler and the PSP Speed

    SceCtrlData pad;

    scePowerSetClockFrequency&#40;166, 166, 166&#41;;

    sceCtrlSetSamplingCycle&#40;0&#41;;

    sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;

	
    

	//Initialize the SDL Library &#40;audio and video&#41;

    if&#40;SDL_Init&#40;SDL_INIT_VIDEO | SDL_INIT_AUDIO&#41; < 0&#41;

		cout << stderr << "Couldn't initialize SDL&#58; " << SDL_GetError&#40;&#41; << endl;



    //Initialize the SDL True Type Font Library

    if&#40;TTF_Init&#40;&#41; < 0&#41;

		cout << stderr << "Couldn't initialize TTF&#58; " << SDL_GetError&#40;&#41; << endl;



    //Initialize the font color.

    SDL_Color white = &#123;255, 255, 255&#125;;

	SDL_Color black = &#123;0, 0, 0&#125;;

	

	//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&#40;480, 272, 32, SDL_HWSURFACE | SDL_DOUBLEBUF&#41;;



    background = SDL_DisplayFormat&#40;IMG_Load&#40;"data/gfx/blackbackground.png"&#41;&#41;;

    //iconCalendar = SDL_DisplayFormatAlpha&#40;IMG_Load&#40;"data/gfx/calendar.png"&#41;&#41;;

	

    //Initialisation du mode Debug de la PSP

	pspDebugScreenInit&#40;&#41;;

    SetupCallbacks&#40;&#41;;

	
	

    //Start the loop

    while&#40;isrunning&#41;

    &#123;		

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

		sceRtcGetCurrentClockLocalTime&#40;&time&#41;;

		

		SDL_BlitSurface&#40;background, NULL, ecran, &background_position&#41;;

		
	
			

		SDL_BlitSurface&#40;mousePointer, NULL, ecran, &mouse&#41;;		

		SDL_Flip&#40;ecran&#41;;

    &#125;

	

    //Free the memory.

	

    SDL_FreeSurface&#40;background&#41;;

    SDL_Quit&#40;&#41;;

	

    sceKernelSleepThread&#40;&#41;;



    return 0;

&#125;

I understand it's a quick example.. Let me know if you anything else

Cheers
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

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.
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

when i compile your code i get this errors:

Code: Select all

/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;eglCreateContext.o&#41;&#58; En la función `eglCreateContext'&#58;
/cygdrive/c/pspgl2/eglCreateContext.c&#58;43&#58; referencia a `pspvfpu_initcontext' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;eglDestroyContext.o&#41;&#58; En la función `eglDestroyContext'&#58;
/cygdrive/c/pspgl2/eglDestroyContext.c&#58;42&#58; referencia a `pspvfpu_deletecontext' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;glLoadIdentity.o&#41;&#58; En la función `glLoadIdentity'&#58;
/cygdrive/c/pspgl2/glLoadIdentity.c&#58;23&#58; referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;pspgl_context.o&#41;&#58; En la función `flush_matrix'&#58;
/cygdrive/c/pspgl2/pspgl_context.c&#58;107&#58; referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;pspgl_matrix.o&#41;&#58; En la función `__pspgl_matrix_sync'&#58;
/cygdrive/c/pspgl2/pspgl_matrix.c&#58;19&#58; referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;pspgl_matrix.o&#41;&#58; En la función `__pspgl_matrix_load'&#58;
/cygdrive/c/pspgl2/pspgl_matrix.c&#58;33&#58; referencia a `pspvfpu_use_matrices' sin definir
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libgl.a&#40;glMultMatrixf.o&#41;&#58; En la función `glMultMatrixf'&#58;
/cygdrive/c/pspgl2/glMultMatrixf.c&#58;17&#58; referencia a `pspvfpu_use_matrices' sin definir
collect2&#58; ld devolvi'o el estado de salida 1
make&#58; *** &#91;Test.elf&#93; 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
VZsolt
Posts: 2
Joined: Mon Sep 10, 2007 3:54 pm

Post by VZsolt »

Check out this thread:
http://forums.qj.net/f-psp-development- ... 39653.html

I was having the same problem, but lostjared's fix solved it!
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Put main() in an extern C block. Search the forums for more info; this has been asked lots of times before.
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

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)
VZsolt
Posts: 2
Joined: Mon Sep 10, 2007 3:54 pm

Post by VZsolt »

IIRC the README.PSP file in SDL has a paragraph about this.
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

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
Post Reply