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 

SDL on PSP, C++ allowed?

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



Joined: 15 May 2005
Posts: 11

PostPosted: Wed Aug 17, 2005 2:18 pm    Post subject: SDL on PSP, C++ allowed? Reply with quote

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



Joined: 15 May 2005
Posts: 11

PostPosted: Wed Aug 17, 2005 2:42 pm    Post subject: Reply with quote

Oddly, this fixed the problem:

Code:

#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]
Back to top
View user's profile Send private message
Thanhda



Joined: 09 Apr 2005
Posts: 331
Location: Canada

PostPosted: Wed Aug 24, 2005 8:13 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message Visit poster's website
rinco



Joined: 21 Jan 2005
Posts: 255
Location: Canberra, Australia

PostPosted: Wed Aug 24, 2005 9:38 am    Post subject: Reply with quote

i'm fairly certain c++ sdl apps only require:
Code:
extern "C" int SDL_main( int argc, char *argv[] )
Back to top
View user's profile Send private message
statikeffeck



Joined: 15 May 2005
Posts: 11

PostPosted: Wed Aug 24, 2005 10:26 am    Post subject: Reply with quote

Thanks rinco! this really simplifies things.
Just don't forget the semicolon at the end of the statement.
I did:
Code:
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;
}
Back to top
View user's profile Send private message
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