forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Question]Can we use CPP in PSP programming progress?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
iEpsilonMeteOra



Joined: 14 Jul 2006
Posts: 6

PostPosted: Tue Jul 18, 2006 4:09 pm    Post subject: [Question]Can we use CPP in PSP programming progress? Reply with quote

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
View user's profile Send private message
the_darkside_986



Joined: 18 Jul 2006
Posts: 9

PostPosted: Tue Jul 18, 2006 4:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Tue Jul 18, 2006 4:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Tue Jul 18, 2006 4:41 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
iEpsilonMeteOra



Joined: 14 Jul 2006
Posts: 6

PostPosted: Tue Jul 18, 2006 4:43 pm    Post subject: I've try add CPP code in PSPSDK samples to compile them. Reply with quote

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
View user's profile Send private message
iEpsilonMeteOra



Joined: 14 Jul 2006
Posts: 6

PostPosted: Tue Jul 18, 2006 5:31 pm    Post subject: Maybe I have successed in compile them in CPP. Reply with quote

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
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Tue Jul 18, 2006 5:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
iEpsilonMeteOra



Joined: 14 Jul 2006
Posts: 6

PostPosted: Tue Jul 18, 2006 6:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Tue Jul 18, 2006 6:36 pm    Post subject: Reply with quote

you just need to download the headers and overwrite the ones you have (just get a svn client)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group