PRX's and C++ vs C

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

Moderators: cheriff, TyRaNiD

Post Reply
Kreationz
Posts: 52
Joined: Sun May 18, 2008 11:01 am

PRX's and C++ vs C

Post by Kreationz »

I've got what is probably a stupid issue but it is bugging me none the less. I can successfully compile this as a C file but not as C++

First let me start with the code:

main.cpp: (compiles as main.c)

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>

#define VERS 0
#define REVS 55

PSP_MODULE_INFO&#40;"HLEAudio", 0x1006, VERS, REVS&#41;;

int module_start &#40;SceSize argc, void* argp&#41;
&#123;
return 0;
&#125;

int module_stop &#40;SceSize args, void *argp&#41;
&#123;
return 0;
&#125;
makefile:

Code: Select all

TARGET = HLEAudio
OBJS = main.o

CFLAGS = -O2 -G0 -DNDEBUG -Wall -MD
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

INCDIR = ../../../SDK/include
LIBDIR = ../../../SDK/lib
BUILD_PRX = 1
PRX_EXPORTS = exports.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LDFLAGS = -mno-crt0 -nostartfiles
LIBS =

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

all&#58; $&#40;FINAL_TARGET&#41;
	cp $&#40;FINAL_TARGET&#41; "../../.."
exports.exp:

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;s
PSP_EXPORT_FUNC&#40;module_stop&#41;
PSP_EXPORT_END

# This is where we export our functions to be called by the main app
PSP_EXPORT_START&#40;HLEAudio, 0, 0x4001&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
Now on to the problem(s):

First when compiling as is if I rebuild it I get an error linking:

Code: Select all

1>C&#58;/pspsdk/bin/rm -f HLEAudio.prx HLEAudio.elf exports.o main.o PARAM.SFO EBOOT.PBP 
1>psp-gcc -IC&#58;/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC&#58;/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150   -c -o main.o main.c
1>psp-build-exports -b exports.exp > exports.c
1>psp-gcc -IC&#58;/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC&#58;/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150   -c -o exports.o exports.c
1>psp-gcc -IC&#58;/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC&#58;/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150  -L../../../SDK/lib -L. -LC&#58;/pspsdk/psp/sdk/lib -specs=C&#58;/pspsdk/psp/sdk/lib/prxspecs -Wl,-q,-TC&#58;/pspsdk/psp/sdk/lib/linkfile.prx -mno-crt0 -nostartfiles  main.o exports.o  -lpspdebug -lpspdisplay_driver -lpspctrl_driver -lpspsdk  -lpspkernel -o HLEAudio.elf
1>psp-fixup-imports HLEAudio.elf
1>Error, no .lib.stub section found
1>C&#58;\pspsdk\bin\make&#58; *** &#91;HLEAudio.elf&#93; Error 1
1>rm exports.c
1>Build log was saved at "file&#58;//f&#58;\PSPDev\DaedalusX64 Curent Code\DX64-Abstracted\Source\SysPSP\AudioPRX\obj\Debug\AudioPRXBuildLog.htm"
1>AudioPRX - 0 error&#40;s&#41;, 0 warning&#40;s&#41;
========== Rebuild All&#58; 1 succeeded, 0 failed, 0 skipped ==========
But afterward if I just build again it compiles.

If I just rename main.c to main.cpp and that is the only change I can't get it to compile at all and get this:

Code: Select all

1>psp-build-exports -b exports.exp > exports.c
1>psp-gcc -IC&#58;/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC&#58;/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150   -c -o exports.o exports.c
1>psp-gcc -IC&#58;/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC&#58;/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150  -L../../../SDK/lib -L. -LC&#58;/pspsdk/psp/sdk/lib -specs=C&#58;/pspsdk/psp/sdk/lib/prxspecs -Wl,-q,-TC&#58;/pspsdk/psp/sdk/lib/linkfile.prx -mno-crt0 -nostartfiles  main.o exports.o  -lpspdebug -lpspdisplay_driver -lpspctrl_driver -lpspsdk  -lpspkernel -o HLEAudio.elf
1>c&#58;/pspsdk/bin/../lib/gcc/psp/4.3.3/../../../../psp/bin/ld.exe&#58; warning&#58; cannot find entry symbol module_start; defaulting to 0000000000000000
1>exports.o&#58;&#40;.rodata.sceResident+0xc&#41;&#58; undefined reference to `module_start'
1>exports.o&#58;&#40;.rodata.sceResident+0x10&#41;&#58; undefined reference to `module_stop'
1>collect2&#58; ld returned 1 exit status
1>C&#58;\pspsdk\bin\make&#58; *** &#91;HLEAudio.elf&#93; Error 1
1>rm exports.c
1>Build log was saved at "file&#58;//f&#58;\PSPDev\DaedalusX64 Curent Code\DX64-Abstracted\Source\SysPSP\AudioPRX\obj\Debug\AudioPRXBuildLog.htm"
1>AudioPRX - 0 error&#40;s&#41;, 1 warning&#40;s&#41;
========== Rebuild All&#58; 1 succeeded, 0 failed, 0 skipped ==========
module_start is obviously there, so what am I missing?
coyotebean
Posts: 18
Joined: Sat Dec 05, 2009 1:02 am

Post by coyotebean »

names in C++ are mangled.
Usually

Code: Select all

extern "C"
are used to keep the name unmangled for interface with C.
Kreationz
Posts: 52
Joined: Sun May 18, 2008 11:01 am

Post by Kreationz »

knew it was something simple. It still takes 2 tries to compile but it is compiling at least.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

if you want to pass c++ classes you will need to do an objdump to get the mangled names and put those in the exports file. you need to include the class functions etc that will be used in the prx

note:
except strings because it will mess up with the memory allocation etc
Post Reply