Compiling an SDL program written in C/C++ for the PSP
Last updated: 16 march 2014
This page details how to compile your SDL program written in C/C++ for the PSP. It came into existence because of the lack of a complete guide.
Source code changes
C
No changes are necessary if your source code is written exclusively in C.
C++
If you use C++ for the file where your main()
is declared, the compiler will complain: "no sceModuleInfo section found". This section it's trying to find is usually added through the MODULE_INFO
macro. However, adding one will not solve the underlying problem.
The problem is that the C++ compiler can't find your main()
, because it's a C function. To solve this, tag it as such, like so:
extern "C" int main(int argc, char* args[])
With your main()
found, SDLmain will be succesfully linked, which also adds the sceModuleInfo
section that the compiler was complaining about in the first place.
Makefile
We'll use the makefile of the controller sample that ships with the SDK as a base:
TARGET = controller_basic
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Basic controller sample
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
The documentation supplied with the PSP port of SDL instructs to add the following lines above the final include:
PSPBIN = $(PSPSDK)/../bin
CFLAGS += $(shell $(PSPBIN)/sdl-config --cflags)
LIBS += $(shell $(PSPBIN)/sdl-config --libs)
However, this setup has PSPBIN pointing to the wrong directory. Below the PSPSDK definition, add the following:
PSPDEV=$(shell psp-config -d)
Then change the PSPBIN definition to the following:
PSPBIN = $(PSPDEV)/bin
Finally, we need to add some libraries. stdc++ is required for a C++ program. pspirkeyb and psppower are required by SDL (for some reason the configuration script doesn't add them by itself). Add the following line to add them:
LIBS += -lstdc++ -lpspirkeyb -lpsppower
Now what?
Customise the makefile for your project by adding the required object files, and change the eboot title to something appropriate.
Before you run make, though, here is some information that might save you some time:
printf()
doesn't work. UsepspDebugScreenPrintf()
instead, which has the same syntax. Windows users: this won't output to a text file called stdout.txt, but to the screen. Hence it's only useful for debugging issues that crop up before the video mode is set.- To log messages to a file, you can redirect std::cout by replacing its stream buffer.
- If your screen surface is a software surface and it's smaller than the PSP's screen resolution, the output will be stretched across the screen.
- A colour bit depth of 24 for the screen surface is not supported.
- Colour keying on hardware surfaces doesn't work. Use the alpha channel instead. The easiest way to do this is by converting your colour keyed surface using
SDL_DisplayFormatAlpha()
. - Add
BUILD_PRX=1
to your makefile to generate a PRX file for use with PSP emulators. - To allow your application to use the later PSP models's extra RAM (normally used for UMD caching), add
PSP_LARGE_MEMORY=1
to your makefile.
Thanks to protomank for contributing some of this information.