| View previous topic :: View next topic |
| Author |
Message |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Wed Nov 02, 2005 2:15 pm Post subject: pspGL C++ errors |
|
|
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: | 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... |
|
| Back to top |
|
 |
Paco
Joined: 09 Oct 2005 Posts: 54
|
Posted: Wed Nov 02, 2005 11:24 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Thu Nov 03, 2005 10:03 am Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
Paco
Joined: 09 Oct 2005 Posts: 54
|
Posted: Thu Nov 03, 2005 11:03 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Thu Nov 03, 2005 12:49 pm Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Thu Nov 03, 2005 7:11 pm Post subject: |
|
|
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 _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Fri Nov 04, 2005 9:27 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Fri Nov 04, 2005 9:35 am Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Fri Nov 04, 2005 10:52 am Post subject: |
|
|
| 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: | | psp-g++ .... -x c psp-setup.c .... | which will force it to compile it as C. |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Sun Nov 06, 2005 6:10 am Post subject: |
|
|
| 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: | | 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: | 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:
$(CC) $(CFLAGS) -c $<
logo.o: logo.raw
bin2o -i logo.raw logo.o logo
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LFLAGS) -o $@
install: all
$(PSP_INSTALL) $(TARGET) --eboot-title="$(TARGET) $(BUILDDATE)" --eboot-icon="ball1.png"
clean:
$(RM) *.d *.o *.a *.elf *.sfo EBOOT.PBP
-include $(wildcard *.d) 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... |
|
| Back to top |
|
 |
|