Skip to main content

Tutorial for Compiling C++ on your PSP with Oslib (Oldschool Library)!

i finally managed to compile C++ code on my PSP.

i completely removed my development environment for psp and began reinstalling:
this time i relied on the MINPSPW project instead of doing all the cygwin stuff. after that i then used the makefile of Neko Grafico and now it compiles with C++.


I am not too happy with all the tutorials out there to get one going creating stuff for the PSP. Especially Oslib with C++. So here a HowTo to set up Oslib with C++ to run from the scratch.


This small turorial guides you how to get going creating C++ applications for your PSP with the OldSchool Library (at the moment of writing that is Oslib Version 2.10 Alpha) with Visual Studio Express 2008. At the end you will have a compiled program that you then can run on your PSP (if you know how). This tutorial will use the tools provided by the MINPSPW project. The advantage of this is that you will not need Cygwin for it to run. For getting this tutorial done you should not need any knowledge about Makefiles or toolchains as long as you are a bit familiar with visual studio and know what to do with the EBOOT.PBP that pops out after you compiled your program/project.
At first i assume you have Visual Studio (Express) installed and working and want to use it for developing Oslib. If you do not have so yet, go to
http://www.microsoft.com/express/vc/
Now you need to install the PSPSDK. But beforehand, you should install MSYS. It can be found here. Download the latest .exe and install it.
After you did the installation, a shell will open up asking you if you want to perform a post install. Press "y". When asked if you have MinGW installed you most probalby will want to press "n". At least you did not install MinGW with this tutorial (plus won't need it). The shell will now ask you to press ENTER. Be a good boy and do so
Now we finally need to install the PSPSDK.For this, go to http://minpspw.sourceforge.net/archives/cat_sdk.html and download the latest version. For this tutorial i took the version PSPSDK 0.7.2., but if there is a newer one i'm pretty sure that'll do just as well.
Download the .exe and install. In the installer, dont forget to tick the checkbox saying that you want VS support.
For a detailed installation instruction, a tutorial on how to install MINPSPW with VC can be found on the jetcube site. You should follow that tutorial for making sure that you set up Visual Studio correctly. At the moment this tutorial is on http://www.jetcube.eu/archives/2008/02/entry_74.html.
Follow the tutorial until the end.
Now it's time to compile in Visual Studio with Oslib. For this, go to http://minpspw.sourceforge.net/archives/cat_devpak.html.Search for "Old School Lib DEVPAK".At the moment of writing the version is "OSLib-2.10". Download it and try to execute it. The installer will probably mourn that some other package is missing and will abort installation. Remember the name of the missing package, and go back to http://minpspw.sourceforge.net/archives/cat_devpak.html, search for the name the installer mentioned, download it and install. Now try again to install the Oslib package you already downloaded.
finally after some tries (after 2 more package-installs for me), the oslib package installer proceeds with the installation. After it sucessfully installed, open up VS. Create a new Makefile project similar to the one that was described in the tutorial (the one that can be found at http://www.jetcube.eu/archives/2008/02/entry_74.html.
in a completely new folder.
Add a main.cpp file to the project.
Go to the oslib wiki page and take the hello world example found here :http://oslib.playeradvance.org/doku.php?id=day2
copy-paste the code to your main.cpp
to test if you really can compile C++, insert the following code into the space below the line saying
"PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER THREAD_ATTR_VFPU);"
and above the line saying
"int main()"

The code that you should insert should be something C++ proprietary so i suggest:

class TestClass{};

now open up the Makefile in your project folder, or if there is none existing yet, create one. Creating it is simple: just create a file with the name "Makefile". Now open it up. Copy paste the following code inside that was provided by Neko Grafico (for which he deserves my special thanks).




TARGET = main
OBJS = main.o

INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =
STDLIBS = -lstdc++ -losl -lpng -lz \
-lpspsdk -lpspctrl -lpspumd \
-lpsprtc -lpsppower -lpspgu \
-lpspaudiolib -lpspaudio -lm -lmikmod

LIBS=$(STDLIBS)$(YOURLIBS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = test
PSP_EBOOT_ICON = ICON0.png


PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak





now copy a small .PNG file into the project directory where your main.cpp and Makefile are placed. Rename the .PNG file to icon0.PNG. Switch to Visual Studio. Press F7 to compile.

That's it, if everything was done correctly you should now have an EBOOT.PBP that you can copy onto your PSP!
Congrats!

Comments

Anonymous said…
You MYSYS link does not exist, what are we supposed to download?
Schmendrick said…
i updated the blog entry which now has the link.

you can just download it from the official site at
http://www.mingw.org/wiki/msys

direct link to the current version would be
http://heanet.dl.sourceforge.net/sourceforge/mingw/MSYS-1.0.10.exe

if all links go dead some time sooner or later, just google for an installer for msys
Anonymous said…
Hi this is Kreationz from DaedalusX64.com

I just wanted to say thx. I had never compiled for PSP before and this allow me to get started on my work on my project. Thx a million you probably have know idea how time and headache you saved or how much this will help the PSP dev scene.
Schmendrick said…
glad to help.

in fact i think the easy get-started tutorials are something very essential for a community to grow. this, and some easy-to-follow tutorials for beginners.
and that was also the reason why i wrote it.
Anonymous said…
i have followed your tut.but i still have problem when i try to compilling this soruce.(press F7).

and here is debug info :

1>------ Build started: Project: psp_checker, Configuration: Debug Win32 ------
1>Performing Makefile project actions
1>psp-gcc -I. -IC:\PSPide\/psp/sdk/include -G4 -Wall -O2 -c -o main.o main.c
1>main.c (501) : error: stray '\26' in program
1>main.c (501) : error: stray '\264' in program
1>main.c (501) : error: stray '\277' in program
1>main.c (501) : error: stray '\321' in program
1>main.c (501) : error: stray '\313' in program
1>main.c (501) : error: expected '=', ',', ';', 'asm' or '__attribute__' before '~' token
1>main.c (501) :8: warning: null character(s) ignored
1>C:\pspsdk\bin\make: *** [main.o] Error 1
1>Build log was saved at "file://c:\pspsdk\psp\sdk\samples\template\psp_checker\Debug\BuildLog.htm"
1>psp_checker - 6 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Schmendrick said…
hmmm...interesting....

ATM i am on longer holidays, cuz of that no response from me so far. i cannot check the code....


first guess is the include file is not found. are you sure it is put in the defined C:\PSPide\/psp/sdk/include directory?

btw the path does not seem to be well formed is it ;)


not sure if the compiler will handle that correctly. if using windows, just use one backslash
Schmendrick said…
yup, seems the path is not well formed.

if you havent done so yet, try it with a correct library path.