SDL on PSP, C++ allowed?

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

Moderators: cheriff, TyRaNiD

Post Reply
statikeffeck
Posts: 11
Joined: Sun May 15, 2005 3:23 pm

SDL on PSP, C++ allowed?

Post by statikeffeck »

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.
statikeffeck
Posts: 11
Joined: Sun May 15, 2005 3:23 pm

Post by statikeffeck »

Oddly, this fixed the problem:

Code: Select all

#ifndef MYCPPFILENAME
#define MYCPPFILENAME

#ifdef __cplusplus
extern "C" {
#endif

// C++ Code goes all here


#ifdef __cplusplus
}
#endif

#endif /* MYCPPFILENAME */
I guess I have to do that for every C++ file.[/code]
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

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.
There are 10 types of people in the world: Those who understand binary, and those who don't...
rinco
Posts: 255
Joined: Fri Jan 21, 2005 2:12 pm
Location: Canberra, Australia

Post by rinco »

i'm fairly certain c++ sdl apps only require:

Code: Select all

extern "C" int SDL_main( int argc, char *argv[] )
statikeffeck
Posts: 11
Joined: Sun May 15, 2005 3:23 pm

Post by statikeffeck »

Thanks rinco! this really simplifies things.
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;
}
Post Reply