pspGL C++ errors

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

pspGL C++ errors

Post by Thanhda »

With the latest version of the pspgl, i cant seem to manage to compile the code in c++. All i did was rename the simple.c and psp-setup.c to *.cpp, I also modified the Makefile to use psp-g++, rather then psp-gcc. and added USE_PSPSDK_LIBC = 1. Even when trying to use this in any other project, i still get an error. With the previous build this method worked.

Here the error i get

Code: Select all

psp-g++ simple.o -g -Wall -O2 -DMODULE_NAME="test-glut" psp-setup.cpp -L/usr/local/pspdev/psp/sdk/lib -L.. -lglut -lGLU -lGL -lm -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpsplibc -lpspuser -lpspkernel -o glut-simple
psp-setup.cpp: In function ‘void setup_callbacks()’:
psp-setup.cpp:173: error: invalid conversion from ‘void*’ to ‘void (*)(PspDebugRegBlock*)’
psp-setup.cpp:173: error:   initializing argument 1 of ‘int pspDebugInstallErrorHandler(void (*)(PspDebugRegBlock*))’
make: *** [glut-simple] Error 1
There are 10 types of people in the world: Those who understand binary, and those who don't...
Paco
Posts: 54
Joined: Sun Oct 09, 2005 6:53 pm

Post by Paco »

C++ has stricter type requirements than C. Check the types you're passing to pspDebugInstallErrorHandler(), I bet you're converting one of them to (void*) and you shouldn't.
Paco
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

Paco wrote:C++ has stricter type requirements than C. Check the types you're passing to pspDebugInstallErrorHandler(), I bet you're converting one of them to (void*) and you shouldn't.
i'm not sure what i am passing it in, i didnt even touch the code, but renamed it to a cpp file and added extern "C" and changed ti to psp-g++

The thing that is different then the previous build is that now there is a psp-setup.c file.
There are 10 types of people in the world: Those who understand binary, and those who don't...
Paco
Posts: 54
Joined: Sun Oct 09, 2005 6:53 pm

Post by Paco »

Thanhda wrote:i didnt even touch the code, but renamed it to a cpp file
That's what I'm saying, C++ has stricter type requirements than C in many cases, and thus some C code that relies on relaxed type checks will not compile if treated as C++.
Paco
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

Paco wrote:
Thanhda wrote:i didnt even touch the code, but renamed it to a cpp file
That's what I'm saying, C++ has stricter type requirements than C in many cases, and thus some C code that relies on relaxed type checks will not compile if treated as C++.
so what do you recommend doing? how can i fix this problem?
There are 10 types of people in the world: Those who understand binary, and those who don't...
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

In C all pointer types are compatible with void *. In C++ they're not. Any place where in C you used this capability, you will have to add a type cast in C++.
eg. in C, this is valid
int *x = malloc(4)
but in C++ you must have
int *x = (int *)malloc(4);

In your case, you're passing a function pointer to a void * type. You need to cast the function pointer to void *, or change the prototype to take something other than void *.

Jim
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Thanhda wrote:i'm not sure what i am passing it in, i didnt even touch the code, but renamed it to a cpp file and added extern "C" and changed ti to psp-g++

The thing that is different then the previous build is that now there is a psp-setup.c file.
Don't convert it to C++; just compile it as C. BTW, 'extern "C"' doesn't make the code be treated as C code, it just makes the external symbols C-compatible; it is still parsed and error-checked as C++ code.
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

jsgf wrote:Don't convert it to C++; just compile it as C. BTW, 'extern "C"' doesn't make the code be treated as C code, it just makes the external symbols C-compatible; it is still parsed and error-checked as C++ code.
But how will this work? you cant compile c files using g++. only using gcc. can you compile a mix between c and cpp files? if so can you post a sample of a makefile that will do this.
There are 10 types of people in the world: Those who understand binary, and those who don't...
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Thanhda wrote:But how will this work? you cant compile c files using g++. only using gcc. can you compile a mix between c and cpp files? if so can you post a sample of a makefile that will do this.
Make will invoke $(CC) to compile .c files, and $(CXX) to compile .cpp files. If your target depends on a.o, b.o and c.o, and there's an a.c, b.cpp, c.f (Fortran), make will invoke the appropriate compiler for each .o (as soon as someone gets g77 ported to the PSP).

So you shouldn't need to do anything to make this work, except use psp-setup.o rather than psp-setup.c in your link line (ie, get make to compile psp-setup.c separately).

Alternatively, you could change the link line to something like:

Code: Select all

psp-g++ .... -x c psp-setup.c ....
which will force it to compile it as C.
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

jsgf wrote:
Thanhda wrote:But how will this work? you cant compile c files using g++. only using gcc. can you compile a mix between c and cpp files? if so can you post a sample of a makefile that will do this.
Make will invoke $(CC) to compile .c files, and $(CXX) to compile .cpp files. If your target depends on a.o, b.o and c.o, and there's an a.c, b.cpp, c.f (Fortran), make will invoke the appropriate compiler for each .o (as soon as someone gets g77 ported to the PSP).

So you shouldn't need to do anything to make this work, except use psp-setup.o rather than psp-setup.c in your link line (ie, get make to compile psp-setup.c separately).

Alternatively, you could change the link line to something like:

Code: Select all

psp-g++ .... -x c psp-setup.c ....
which will force it to compile it as C.
Okay, i'm not too familiar with makefiles, so if i was to do the first method, what would it end up as? heres the current default makefile.

Code: Select all

ARCH = psp-
CC = $(ARCH)gcc
PSP_INSTALL = ../tools/psp-install
RM = rm -f

PSPPATH := $(shell psp-config --pspsdk-path)
PSPGL_LFLAGS = -lGLU -lGL -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lm -lc -lpspuser -lpsputility -lpspkernel
CFLAGS = -g -Wall -O2 -MD -I$(PSPPATH)/include -I..
LFLAGS = -g -Wall -O2 -DMODULE_NAME="test-egl" psp-setup.c -L$(PSPPATH)/lib -L.. $(PSPGL_LFLAGS)

TARGET = pspGL-cube
OBJS = eglcube.o logo.o

BUILDDATE = $(shell date "+%Y/%m/%d %k:%M:%S")

PSPSDK=$(shell psp-config --pspsdk-path)


all: $(TARGET)

.c.o:
        $&#40;CC&#41; $&#40;CFLAGS&#41; -c $<

logo.o&#58; logo.raw
        bin2o -i logo.raw logo.o logo

$&#40;TARGET&#41;&#58; $&#40;OBJS&#41;
        $&#40;CC&#41; $&#40;OBJS&#41; $&#40;LFLAGS&#41; -o $@

install&#58; all
        $&#40;PSP_INSTALL&#41; $&#40;TARGET&#41; --eboot-title="$&#40;TARGET&#41; $&#40;BUILDDATE&#41;" --eboot-icon="ball1.png"

clean&#58;
        $&#40;RM&#41; *.d *.o *.a *.elf *.sfo EBOOT.PBP

-include $&#40;wildcard *.d&#41; dummy
For the secondary method, how exactly do i compile it sperately? then link it later?
There are 10 types of people in the world: Those who understand binary, and those who don't...
Post Reply