(C++) PSP compile problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Christer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 44
Joined: Thu Feb 05, 2009 12:39 pm
Location: Sweden

(C++) PSP compile problem

Post by Christer »

I have been trying to compile a simple .cpp file with some SDL stuff inside with the MINPSPW. But I keep getting errors that the SDL stuff is not defined..

I finaly got C++ to code to compile before I had problems with that and could only compile C code. I use this make file for C++ code:

Code: Select all

TARGET = main

PSP_FW_VERSION = 150
USE_PSPSDK_LIBC = 0
USE_USER_LIBS = 1

OBJS =	main.o

CFLAGS		= -O2 -G0 -Wall
CXXFLAGS	= $(CFLAGS) -fno-exceptions -fno-rtti -fno-strict-aliasing -fsingle-precision-constant -msingle-float
ASFLAGS		= $(CFLAGS)

LIBS =	-lpsputility -lpspgu -lpspumd -lpsprtc -lpsppower -lstdc++ -lm

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = TestProgram

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
And when I want to use SDL I use this makefile but then I can only program with C code:

Code: Select all

TARGET = main
OBJS = main.o

PSPSDK = $(shell psp-config --pspsdk-path)
PSPDEV = $(shell psp-config -d)
PSPBIN = $(PSPDEV)/bin
SDL_CONFIG = $(PSPBIN)/sdl-config

CFLAGS = -O2 -G0 -Wall -D PSP
CFLAGS += $(shell $(SDL_CONFIG) --cflags)
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBS = -lstdc++ -lSDL_ttf -lfreetype -lSDL_image -ljpeg -lpng -lz -lm -lSDL_mixer -lvorbisidec -lmikmod -lmad $(shell $(SDL_CONFIG) --libs)
LIBS += -lpspaudiolib -lpspaudio -lpsppower

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = TestProgram

include $(PSPSDK)/lib/build.mak
So basicly my question is how the makefile should look like if I want to compile C++ code with SDL stuff. I have tried to add the LIBS and that stuff from the SDL make file to the other makefile but it don't help. Anyone could help me?

Sorry for my poor English I hope you understand what I'm trying to say.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: (C++) PSP compile problem

Post by Falco Girgis »

From what I remember from screwing with the psp toolchain's makefile, it invokes gcc or g++ depending on whether your extensions are .c or .cpp--so it should be invoking the C++ compiler fine for the second makefile.

Could I see some errors when trying to use C++?
User avatar
Christer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 44
Joined: Thu Feb 05, 2009 12:39 pm
Location: Sweden

Re: (C++) PSP compile problem

Post by Christer »

When I try to compile this main.cpp:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>

#include <stdio.h>

#include <sdl.h>
#include <sdl_image.h>

//PSP_MODULE_INFO("CONTROLTEST", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

void dump_threadstatus(void);
int done = 0;

int exit_callback(int arg1, int arg2, void *common)
{
	done = 1;
	return 0;
}
int CallbackThread(SceSize args, void *argp)
{
	int cbid;
	cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
	sceKernelRegisterExitCallback(cbid);
	sceKernelSleepThreadCB();
	return 0;
}
int SetupCallbacks(void)
{
	int thid = 0;
	thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
	if(thid >= 0)
	{
		sceKernelStartThread(thid, 0, 0);
	}
	return thid;
}

void DrawImage( SDL_Surface * src_surface, int x, int y, SDL_Surface * dest_surface )
{
    // Here, we construct a rectangle representing the entire image.
    SDL_Rect src_rect ;
    src_rect.x = 0 ;
    src_rect.y = 0 ;
    src_rect.w = src_surface->w ;
    src_rect.h = src_surface->h ;

    // We construct a rectangle representing where we want the
    // image to be located on the destination surface.
    SDL_Rect dest_rect ;
    dest_rect.x = x ;
    dest_rect.y = y ;

    // This is where all the magic happens. The source surface
    // is mapped onto the destination surface.
    SDL_BlitSurface( src_surface, &src_rect, dest_surface, &dest_rect ) ;
}


int main(void)
{
	SceCtrlData pad;

	pspDebugScreenInit();
	SetupCallbacks();

	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	SDL_Surface *screen, *img;

	screen = SDL_SetVideoMode(480, 272, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
	img = IMG_Load("test.png");
	SDL_FillRect(screen,NULL, 0x000000); //Clear screen
	DrawImage(img, 0, 0, screen);
	SDL_Flip(screen); 
	

	while(!done)
	{
		pspDebugScreenSetXY(0, 2);
		sceCtrlReadBufferPositive(&pad, 1); 
	}

	SDL_FreeSurface(img);
	sceKernelExitGame();
	return 0;
}

I get this error:

Code: Select all

C:\pspsdk\psp\christer\New>make
psp-g++ -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D PSP -IC:/pspsdk/psp/inc
lude/SDL -Dmain=SDL_main  -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D PSP -
IC:/pspsdk/psp/include/SDL -Dmain=SDL_main  -fno-exceptions -fno-rtti -D_PSP_FW_
VERSION=150   -c -o main.o main.cpp
psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D PSP -IC:/pspsdk/psp/inc
lude/SDL -Dmain=SDL_main  -D_PSP_FW_VERSION=150  -L. -LC:/pspsdk/psp/sdk/lib   m
ain.o -lstdc++ -lSDL_ttf -lfreetype -lSDL_image -ljpeg -lpng -lz -lm -lSDL_mixer
 -lvorbisidec -lmikmod -lmad -LC:/pspsdk/psp/lib -lSDLmain -lSDL -lm -lGL -lpspv
fpu -LC:/pspsdk/psp/sdk/lib -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -l
psphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lps
pnet_inet  -lpspaudiolib -lpspaudio -lpsppower -lpspdebug -lpspdisplay -lpspge -
lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -l
psputility -lpspuser -lpspkernel -o main.elf
C:/pspsdk/psp/lib\libSDLmain.a(SDL_psp_main.o): In function `main':
psp/SDL_psp_main.c:86: undefined reference to `SDL_main'
collect2: ld returned 1 exit status
make: *** [main.elf] Error 1
Using this makefile:

Code: Select all

TARGET = main
OBJS = main.o

PSPSDK = $(shell psp-config --pspsdk-path)
PSPDEV = $(shell psp-config -d)
PSPBIN = $(PSPDEV)/bin
SDL_CONFIG = $(PSPBIN)/sdl-config

CFLAGS = -O2 -G0 -Wall -D PSP
CFLAGS += $(shell $(SDL_CONFIG) --cflags)
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBS = -lstdc++ -lSDL_ttf -lfreetype -lSDL_image -ljpeg -lpng -lz -lm -lSDL_mixer -lvorbisidec -lmikmod -lmad $(shell $(SDL_CONFIG) --libs)
LIBS += -lpspaudiolib -lpspaudio -lpsppower

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Ohaspii

include $(PSPSDK)/lib/build.mak
I don't get any errors if I name it main.c.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: (C++) PSP compile problem

Post by Falco Girgis »

Try changing your

Code: Select all

int main(void)
to

Code: Select all

int main(int argc, char *argv[])
I'm not sure about the PSP, but on the PC, SDLMain looks for that function signature.

...though if the C file worked with int main(void), that wouldn't make any sense at all...
User avatar
Christer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 44
Joined: Thu Feb 05, 2009 12:39 pm
Location: Sweden

Re: (C++) PSP compile problem

Post by Christer »

GyroVorbis wrote:Try changing your

Code: Select all

int main(void)
to

Code: Select all

int main(int argc, char *argv[])
I'm not sure about the PSP, but on the PC, SDLMain looks for that function signature.

...though if the C file worked with int main(void), that wouldn't make any sense at all...
I tried to change to int main(int argc, char *argv[]) but I still get the same error.
User avatar
epicasian
Chaos Rift Junior
Chaos Rift Junior
Posts: 232
Joined: Mon Feb 22, 2010 10:32 pm
Current Project: Gigazilla Engine
Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
Programming Language of Choice: C/++
Location: WoFo, KY

Re: (C++) PSP compile problem

Post by epicasian »

I'm just guessing (because I've never used the PSP SDK) but, are you linking to the main SDL lib? I didn't see anything like -lSDL in your makefile, but I might of missed it.
User avatar
Christer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 44
Joined: Thu Feb 05, 2009 12:39 pm
Location: Sweden

Re: (C++) PSP compile problem

Post by Christer »

epicasian wrote:I'm just guessing (because I've never used the PSP SDK) but, are you linking to the main SDL lib? I didn't see anything like -lSDL in your makefile, but I might of missed it.
I tried with adding -lSDL but no change. I don't think that's not really the problem. Because I can compile it and it will work if I change the extension from .cpp to .c but I want to compile c++ code and not only c.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: (C++) PSP compile problem

Post by Ginto8 »

SDL_main should not even exist on PSP. I don't think you have the PSP SDL libs. SDL_main exists because, on windows, graphical applications use a WinMain (that's the correct capitalization iirc), so SDL_main exists so that you can use main()
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply