| View previous topic :: View next topic |
| Author |
Message |
iEpsilonMeteOra
Joined: 14 Jul 2006 Posts: 6
|
Posted: Tue Jul 18, 2006 4:09 pm Post subject: [Question]Can we use CPP in PSP programming progress? |
|
|
| I have found that almost all the PSPSDK samples was wrote by C, not CPP. Can we develop homebrew application by using CPP for PSP? |
|
| Back to top |
|
 |
the_darkside_986
Joined: 18 Jul 2006 Posts: 9
|
Posted: Tue Jul 18, 2006 4:13 pm Post subject: |
|
|
| I had the same trouble trying to use the "graphics.c" and "graphics.h" (from the six main PSP dev tutorials) as C++ files for my main.cpp, even after I changed graphics.c to graphics.cpp. I kept getting weird linker errors so I gave up and started learning some C. It's about the same, just harder and messier. I'm still wondering if there is a solution. |
|
| Back to top |
|
 |
Drakonite Site Admin

Joined: 17 Jan 2004 Posts: 989
|
Posted: Tue Jul 18, 2006 4:39 pm Post subject: |
|
|
Those graphics.c and graphics.h files are not part of pspsdk.
Everything in pspsdk should work with C++. Just remember there are numerous things to avoid with C++ on console hardware and it can be very easy to slaughter performance because of the extra cruft that can get added. _________________ Shoot Pixels Not People!
Makeshift Development |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Tue Jul 18, 2006 4:41 pm Post subject: |
|
|
those files are from the lua graphic library.
(note these steps could require cygwin or similar program if you aren't in linux)
now the luaplayer use a c++ version of that library and to get it to work you need first to download from svn libjpeg and build/install it, then libpng and build/install, libz and build/install it finally the cpplibs and build at least the libpsp2d and install it into your enviroment.
After that download from svn the luaplayer and go in the src folder and take out from there the graphic.h, graphic.cpp, framebuffer.h, framebuffer.cpp.
make a makefile similar to this:
| Code: |
PSPDIR=$(PSPDEV)
TARGET_LIB = libluagraphicpp.a
OBJS = framebuffer.o graphics.o
CFLAGS = -O2 -G0
include $(PSPSDK)/lib/build.mak |
make it and you will obtain a libluagraphic.a lib.
copy it into the psp/lib folder and add to your apps the header file you copied before and use a string similar to this in the LIBS= declaration in the makefile of your apps
LIBS = -lluagraphicpp -lpsp2d -lstdc++ -ljpeg -lpng -lz -lpspgu -lm (add other libs also if you need them) |
|
| Back to top |
|
 |
iEpsilonMeteOra
Joined: 14 Jul 2006 Posts: 6
|
Posted: Tue Jul 18, 2006 4:43 pm Post subject: I've try add CPP code in PSPSDK samples to compile them. |
|
|
| I've try add CPP code in PSPSDK samples to compile them. But I failed just now. The linker shows me some link error information about functions named likes sce*() in $(PSPSDK)\lib. So I guess we don't have the libary which compiled in CPP form. Maybe we should generate these lib files in CPP by myself? Can anyone help us? |
|
| Back to top |
|
 |
iEpsilonMeteOra
Joined: 14 Jul 2006 Posts: 6
|
Posted: Tue Jul 18, 2006 5:31 pm Post subject: Maybe I have successed in compile them in CPP. |
|
|
I've try to modify the samples code listed in the PSPSDK\samples\gu\cube. And wanna to make it can be compiled with psp-g++. Now, I make it successfully. But I have not try it on my babe PSP.
1, Add two OO source code file named cppTest.h & cppTest.cpp. Adjust the cube.c into cube.cpp. Because this file can be compiled with psp-g++ in only this way.
2, In cppTest.h & cppTest.cpp, I wrote a simple OO class and its implement.
3, In cube.cpp, include the file named cppTest.h and the important thing is add these code listed below:
| Code: | #include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
#include <pspgum.h>
//! -- PA Here !!
#ifdef __cplusplus
extern "C" {
#endif
#include "../common/callbacks.h"
#include "../common/vram.h"
#include "cppTest.h" |
and at the end of this file alse add:
| Code: | sceKernelExitGame();
return 0;
}
//! -- PA Here!!
#ifdef __cplusplus
}
#endif |
OK, Now we can use the class in cube.cpp without any link error.
PS: I don't know how to update the src code in this forum. So sorry about I am not able to upload the code files. |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Tue Jul 18, 2006 5:44 pm Post subject: |
|
|
Err, so in effect, you've wrapped the entire project in a "build it as C instead of C++". Not really C++ then, is it? The stuff in '../common/' shared by the gu-samples have not been written with C++ in mind so they won't work out of the box. I've updated the headers for these files in svn to work in a C++ environment, so they should work just fine from now on. _________________ GE Dominator |
|
| Back to top |
|
 |
iEpsilonMeteOra
Joined: 14 Jul 2006 Posts: 6
|
Posted: Tue Jul 18, 2006 6:21 pm Post subject: |
|
|
| Oops, gu-samples won't works out of box?(Box? Sorry, I can't catch it because I'm a Chinese.). I just adjust the code can be compiled in CPP compiler(More compatible maybe). Maybe it also works all right. I will check it later. I use the devkitPro env in Win32 and I am not able to link the svn to get lastest PSPSDK. |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Tue Jul 18, 2006 6:36 pm Post subject: |
|
|
| you just need to download the headers and overwrite the ones you have (just get a svn client) |
|
| Back to top |
|
 |
|