working C++ samples?

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
lantus
Posts: 10
Joined: Tue May 10, 2005 12:09 pm

working C++ samples?

Post by lantus »

has anyone managed to build a C++ project?

by that i mean as an example take nem's hello world source, rename *.c to *.cpp and link to libSTDC++. I've tried everything and cant get it to link correctly.

anyone have a solution?
xSnes9x - Snes9x Emulation for Xbox Consoles
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

The short answer is that you can't use libstdc++ on the PSP because in the toolchain nem uses libstdc++ was built for the PS2's EE which has a different executable and instruction format than the PSP. See this thread for details: http://forums.ps2dev.org/viewtopic.php?p=11410#11410

The solution is to roll your own GCC toolchain targetted specifically for the PSP's R4K CPU, or wait for someone else to do it.
t3ddY
Posts: 12
Joined: Sun May 08, 2005 12:34 am
Location: The Netherlands

Post by t3ddY »

I managed to get ee-g++ working and make a elf. But the thing was, it didn't run on PSPE and since i don't have a 1.0 jap psp, i couldn't try it myself...

But it's very simple, take the hello world example en compile it with ee-g++... put the xmain in a extern "C" { } if it can't find it and add -fno-exceptions to ee-ld...

Maybe it will run on actual hardware, can't test it from here :(
Treat
Posts: 16
Joined: Sun Sep 26, 2004 10:17 pm

Post by Treat »

it works just fine on hardware
User avatar
lantus
Posts: 10
Joined: Tue May 10, 2005 12:09 pm

Post by lantus »

excellent thanks for checking it out Treat
xSnes9x - Snes9x Emulation for Xbox Consoles
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

what exactly is the point in compiling the code as C code with g++? (that's what extern "C" does?)
Last edited by weak on Fri May 27, 2005 12:46 am, edited 1 time in total.
User avatar
cwbowron
Posts: 76
Joined: Fri May 06, 2005 4:22 am
Location: East Lansing, MI
Contact:

Post by cwbowron »

weak wrote:what exactly is the point in compiling the code as C code with g++? (that's what extern "C" does)
extern "C" tells the compiler not to mangle the name so that it can be exported correctly to the linker. It does not force it to compile as C code.

C++ compilers usually mangle the function name by including information about its arguments and such in the exported symbol.
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

my bad. thx for the clarification.
t3ddY
Posts: 12
Joined: Sun May 08, 2005 12:34 am
Location: The Netherlands

Post by t3ddY »

If you want to check the output, just check the helloworld.map in the mk.bat script... you will see that c++ functionnames will be named differently then c functionnames...

With extern "C" you prevent this.
Zeta
Posts: 9
Joined: Sat Jul 09, 2005 1:46 pm

Post by Zeta »

I've been taking a look at the samples from the sdk in svn and in one of my tests I wanted to compile some samples in c++ (it should be just changing the extension to cpp right?). The result was that some projects compiled and linked ok but others (specially when using the psppower lib) wouldn't link but compiled fine. The thing is that it couldn't resolve functions like scePowerIsBatteryExist, scePowerRegisterCallback, etc...
Can somebody tell me what can be happening here? Is it possible that when switching to c++ the declaration of the function is different than the code on the library?
Thank you very much in advance.
Post Reply