SDL - How to disable SDL_main?

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

Moderators: cheriff, TyRaNiD

Post Reply
tobiasbp
Posts: 5
Joined: Sat Apr 22, 2006 7:53 pm
Location: Denmark

SDL - How to disable SDL_main?

Post by tobiasbp »

Hello....

I want to add sound to my C game using SDL. I have installed SDL and SDL_mixer.

As I allready have my program written with the PSPSDK callbacks I dont want SDL to add those to my main().

I dont really understand the documentation (shown at end of post).

It says:
"Of course, you can leave off -lSDLmain, and write the real main()
yourself if you need more control than this."

I have not added -lSDLmain to my libs. So according to the above it should be off right? It's not however.


The documentation then says:
"By default, the PSP "sdl-config --cflags" will define main=SDL_main."

Does that mean I have to change the sdl-config script to disable main=SDL_main?


Here is my Makefile:
TARGET = tileDraw
OBJS = main.o graphics.o framebuffer.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LIBS = -lpspgu -lpng -lz -lm -lSDL_mixer
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Image Example

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

PSPBIN = $(PSPSDK)/../bin
CFLAGS += $(shell $(PSPBIN)/sdl-config --cflags)
LIBS += $(shell $(PSPBIN)/sdl-config --libs)

include $(PSPSDK)/lib/build.mak


From the SDL documentation:

SDL_main
--------
When writing an SDL program, the typical use is to write your main
function as "SDL_main", then link -lSDLmain which provides the real
main(). In this implementation, -lSDLmain will:
- Define the required PSP_* macros
- Set up the "home" button callback.
- Initialize the debugging screen
- Call the user-supplied SDL_main
- When it returns, delay 2.5 seconds, then exit to VSH.

Of course, you can leave off -lSDLmain, and write the real main()
yourself if you need more control than this.

By default, the PSP "sdl-config --cflags" will define main=SDL_main.


Building applications
---------------------
Write your source file as you would a normal SDL program. Use the standard
Makefile as supplied with any PSPSDK sample program. Above the final "include"
line, add:

PSPBIN = $(PSPSDK)/../bin
CFLAGS += $(shell $(PSPBIN)/sdl-config --cflags)
LIBS += $(shell $(PSPBIN)/sdl-config --libs)



Thanks
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Re: SDL - How to disable SDL_main?

Post by jimparis »

tobiasbp wrote:The documentation then says:
"By default, the PSP "sdl-config --cflags" will define main=SDL_main."

Does that mean I have to change the sdl-config script to disable main=SDL_main?
I would recommend that you use "sed" inside the Makefile to remove the parts of sdl-config that you don't want, like this:

Code: Select all

CFLAGS += $(shell $(PSPBIN)/sdl-config --cflags | sed s/-Dmain=SDL_main//)
LIBS += $(shell $(PSPBIN)/sdl-config --libs | sed s/-lSDLmain//)
If you do this, your "main" becomes the actual main function, and libSDLmain.a will not be used.
tobiasbp
Posts: 5
Joined: Sat Apr 22, 2006 7:53 pm
Location: Denmark

Post by tobiasbp »

I never did make the disabling of SDL_main work. I commented out the PSP specific setup commands in my C file and things appear to be working.

Thanks for your help.
Post Reply