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 

PRX's and C++ vs C

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



Joined: 18 May 2008
Posts: 53

PostPosted: Thu Jan 21, 2010 3:48 pm    Post subject: PRX's and C++ vs C Reply with quote

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:
#include <pspsdk.h>
#include <pspkernel.h>

#define VERS 0
#define REVS 55

PSP_MODULE_INFO("HLEAudio", 0x1006, VERS, REVS);

int module_start (SceSize argc, void* argp)
{
return 0;
}

int module_stop (SceSize args, void *argp)
{
return 0;
}


makefile:
Code:
TARGET = HLEAudio
OBJS = main.o

CFLAGS = -O2 -G0 -DNDEBUG -Wall -MD
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

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=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

all: $(FINAL_TARGET)
   cp $(FINAL_TARGET) "../../.."


exports.exp:
Code:
# Define the exports for the prx
PSP_BEGIN_EXPORTS

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

# This is where we export our functions to be called by the main app
PSP_EXPORT_START(HLEAudio, 0, 0x4001)
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:
1>C:/pspsdk/bin/rm -f HLEAudio.prx HLEAudio.elf exports.o main.o PARAM.SFO EBOOT.PBP
1>psp-gcc -IC:/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC:/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:/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150   -c -o exports.o exports.c
1>psp-gcc -IC:/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150  -L../../../SDK/lib -L. -LC:/pspsdk/psp/sdk/lib -specs=C:/pspsdk/psp/sdk/lib/prxspecs -Wl,-q,-TC:/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:\pspsdk\bin\make: *** [HLEAudio.elf] Error 1
1>rm exports.c
1>Build log was saved at "file://f:\PSPDev\DaedalusX64 Curent Code\DX64-Abstracted\Source\SysPSP\AudioPRX\obj\Debug\AudioPRXBuildLog.htm"
1>AudioPRX - 0 error(s), 0 warning(s)
========== Rebuild All: 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:
1>psp-build-exports -b exports.exp > exports.c
1>psp-gcc -IC:/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150   -c -o exports.o exports.c
1>psp-gcc -IC:/pspsdk/psp/sdk/include/libc -I../../../SDK/include -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -DNDEBUG -Wall -MD -D_PSP_FW_VERSION=150  -L../../../SDK/lib -L. -LC:/pspsdk/psp/sdk/lib -specs=C:/pspsdk/psp/sdk/lib/prxspecs -Wl,-q,-TC:/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:/pspsdk/bin/../lib/gcc/psp/4.3.3/../../../../psp/bin/ld.exe: warning: cannot find entry symbol module_start; defaulting to 0000000000000000
1>exports.o:(.rodata.sceResident+0xc): undefined reference to `module_start'
1>exports.o:(.rodata.sceResident+0x10): undefined reference to `module_stop'
1>collect2: ld returned 1 exit status
1>C:\pspsdk\bin\make: *** [HLEAudio.elf] Error 1
1>rm exports.c
1>Build log was saved at "file://f:\PSPDev\DaedalusX64 Curent Code\DX64-Abstracted\Source\SysPSP\AudioPRX\obj\Debug\AudioPRXBuildLog.htm"
1>AudioPRX - 0 error(s), 1 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


module_start is obviously there, so what am I missing?
Back to top
View user's profile Send private message
coyotebean



Joined: 05 Dec 2009
Posts: 26

PostPosted: Thu Jan 21, 2010 3:58 pm    Post subject: Reply with quote

names in C++ are mangled.
Usually
Code:
extern "C"
are used to keep the name unmangled for interface with C.
Back to top
View user's profile Send private message
Kreationz



Joined: 18 May 2008
Posts: 53

PostPosted: Thu Jan 21, 2010 4:28 pm    Post subject: Reply with quote

knew it was something simple. It still takes 2 tries to compile but it is compiling at least.
Back to top
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Sun Jan 24, 2010 2:33 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
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