I've spent tonight trying to get a simple SDL test program (in C++) to compile. I am able to compile any working C programs that use SDL.
My simple test program doesn't even use any C++ specific code (it actually compiles when I rename the file from main.cpp to main.c). But I would like to work in C++ if possible.
Here's the error I'm getting:
$ make
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I/usr/local/pspdev/psp/include/SDL -Dmain=SDL_main -I. -I
/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I/usr/local/pspdev/psp/include/SDL -Dmain=SDL_main -fno-exceptions -fno
-rtti -c -o main.o main.cpp
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I/usr/local/pspdev/psp/include/SDL -Dmain=SDL_main -L. -
L/usr/local/pspdev/psp/sdk/lib main.o -L/usr/local/pspdev/psp/lib -lSDLmain -lSDL -lm -L/usr/local/pspdev/psp/sdk/lib
-lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspaudio -lc -lpspuser -lpspkernel -lpspdebug -lpspdisplay
-lpspge -lpspctrl -lpspsdk -lc -lpspuser -lpspkernel -o SDLTEST1.elf
/usr/local/pspdev/psp/lib/libSDLmain.a(SDL_psp_main.o): In function `main':
psp/SDL_psp_main.c:76: undefined reference to `SDL_main'
collect2: ld returned 1 exit status
make: *** [SDLTEST1.elf] Error 1
Keep in mind that everything works fine if I rename main.cpp to main.c
EDIT: Also, I just downloaded and installed the SDL library today using svn, so it should be up to date.
SDL on PSP, C++ allowed?
-
- Posts: 11
- Joined: Sun May 15, 2005 3:23 pm
Oddly, this fixed the problem:
I guess I have to do that for every C++ file.[/code]
Code: Select all
#ifndef MYCPPFILENAME
#define MYCPPFILENAME
#ifdef __cplusplus
extern "C" {
#endif
// C++ Code goes all here
#ifdef __cplusplus
}
#endif
#endif /* MYCPPFILENAME */
i've actually manage to compile a C++ project, i used one of the samples, and renamed it to a cpp file. added a class to the project without having to extern "C". but when i try to instanciate a new object it gives me problems.
Edit:
okay heres how to compile C++ files. you have to modify the Makefile
add this
USE_PSPSDK_LIBC = 1
CFLAGS = -O2 -G0 -Wall
and then add the extern "C" in source code.
Edit:
okay heres how to compile C++ files. you have to modify the Makefile
add this
USE_PSPSDK_LIBC = 1
CFLAGS = -O2 -G0 -Wall
and then add the extern "C" in source code.
There are 10 types of people in the world: Those who understand binary, and those who don't...
i'm fairly certain c++ sdl apps only require:
Code: Select all
extern "C" int SDL_main( int argc, char *argv[] )
-
- Posts: 11
- Joined: Sun May 15, 2005 3:23 pm
Thanks rinco! this really simplifies things.
Just don't forget the semicolon at the end of the statement.
I did:
Just don't forget the semicolon at the end of the statement.
I did:
Code: Select all
extern "C" int SDL_main( int argc, char *argv[] );
#include "MyObject.h" // some object header file
int SDL_main(int argc, char *argv[])
{
MyObject newObj;
newObj.doStuff();
return 0;
}