Using C++ and Libraries with a prx

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Using C++ and Libraries with a prx

Post by coolkehon »

i posted something similar to this before but this is different

How can i compile a user mode prx that uses c++ classes and linking because when i use extern "C" {} it wont compile because the objects like a object defined but not initialized in the cpp file as a local variable only visible in the cpp file are not recognized or even seen for that matter inside of the cpp file oh and it wont compile period without extern "C" even if it is c code and i change the file to a cpp file
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You'll need to call the initializers from the module start routine. Look at how the normal start code calls the initializers, then put something similar in the start. Then when the prx is loaded, it should call the init routines.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

J.F. wrote:You'll need to call the initializers from the module start routine. Look at how the normal start code calls the initializers, then put something similar in the start. Then when the prx is loaded, it should call the init routines.
uuuuuuuuuh what can you explain this again in idiots term because i dont understand this kinda new to c++ and pspsdk and psp programming
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

No, I can't. This isn't a task for idiots (pardon my French). You'll need to know more about low-level C++ support before you can do this, or get someone else to take care of that for you. Personally, I can't stand C++, so don't look to me for this. Sorry.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

anyone else care to take a gander at this
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

basically i dont like having to use extern "C" and the c linking with EBOOT.PBP you can use c++ just fine with no extern "C" but why is it so different when doing a prx and could someone just explain what that guy said
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Read this thread for an idea of what's going on...

http://forums.ps2dev.org/viewtopic.php?t=778
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

ok i read it, alot of stuff i didnt understand, so what i still dont get it how come it works on an eboot but not a prx , i'm a beginner when it comes to this topic, doesnt the eboot and prx use the same gcc compiler
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

coolkehon wrote:ok i read it, alot of stuff i didnt understand, so what i still dont get it how come it works on an eboot but not a prx , i'm a beginner when it comes to this topic, doesnt the eboot and prx use the same gcc compiler
The EBOOT elf has crt0.S included into it, which calls the functions talked about. The prx specifically DOESN'T have crt0.S included... it's in the makefile not to! You'll have to take the code needed from crt0.S and insert it into the module start code to do the same thing. I'm not sure that will work since I don't believe anyone has tried making C++ prx's. You'll be in uncharted territory and have to work much of it out yourself.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

thanks for your help on this and i see what your saying now but seems like i remeber something about the eboot calling module_start also i know thats off topic , now about that crt0.S can i just put the crt0.S in my makefile and it work or is there something else needed, one more thing what about prx's that have their own int main(int args,void *args[]) do they have crt0.S included, and one more thing when a int main() prx's main thread ends does the module end and unload itself to where the exports can be called or what thanks for your help
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

In the thread where I posted the example user prx, I posted that not making a main thread in the prx makes the app call the module_start on it's own thread. That's probably what you're thinking of.

You might want to read the PDF on PSP modules that was linked in one of your threads. It's got all the info you need, but it's pretty deep. It's not really meant for beginners. That will have the info on prx's that have a main thread with a main() entry. I don't think you need that in your case. Also, the question about the module stopping/unloading will be in the PDF as well. It's a good read, but it'll be tough since you're just starting at this.

You can't use the regular crt0.s in your prx as it's not meant for such a thing. It's meant for starting a full app, not a loadable library. You pretty much want to copy the portion that inits the C++ junk and forget the rest.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

so how do i know what is the c++ junk and what is not
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Try googling on the info in that thread I linked above. You'll have to track it down through web articles or find someone with that level of C++ knowledge.
Post Reply