Linking to SDLmain

OK, so I’m writing a pacmac clone on SDL, and on my
windows laptop it compiles and runs fine.

On my PS2linux box, it can’t link.

Here’s the problem: it comlpains about an undefined
reference to SDL_main. However, my main.cpp file has
in it:

int SDL_main(int argc, char** argv)
{

}

which I believe is the correct prototype (I don’t
think prototype is the correct word here, but you know
what I mean.

If I change the SDL_main to main and remove the
-lSDLmain flag from the compile options, then it all
works fine, if I leave the option in I get an error
aobut a duplicate definiton of main.

Where am I going wrong? What should the link line of
my Makefile look like? Right now, it’s something
like:

sdlpac: game.o, main.o … some other .o’s
$(LD) -g -lSDLmain sdl-config --libs -o
sdlpac game.o main.o …

Any ideas? The documentation project just uses main,
which is no use for Win32 stuff. Also, I think it’s a
little strange that sdl-config --libs doesn’t provide
-lSDLmain for me, I had to put that in myself.

Basicaly I’m after the ‘best practice’:

-Should I call my ‘main’ function main() or
SDL_main()?
-Should I link to libSDLmain.a explicitly?

Any pointers welcome… Also (somewhat OT) is the doc
project still active? Who is the best person to talk
to about helping in this respect, I would love to add
to the SDL guide section, my coding isn’t good enough
to contribute source code to the project so I’d like
to help!

Paul

PS As I’ve been writing this, I’ve come up with a
solution. I leave the main function as main(), not
SDL_main, and I only link with -lSDLmain on the Win32
box, not on the linux box. Is this ‘best practice’?__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

[…]

-Should I call my ‘main’ function main() or
SDL_main()?

You should call in main(). SDL redefines the word “main” as required.
(Differs between platforms, which is why other variants work
occasionally.)

-Should I link to libSDLmain.a explicitly?

Well, on some platforms, you should - but it’s much nicer to ask the
’sdl-config’ script about that. It Just Works™.

My native Linux install of SDL says:

-L/usr/local/lib -Wl,-rpath,/usr/local/lib -lSDL -lpthread

while my Win32 cross-compiler install says:

-L/usr/local/cross-tools/i386-mingw32msvc/lib -lmingw32
		-lSDLmain -lSDL -mwindows

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Tuesday 10 September 2002 15:56, Paul Smith wrote:

Any ideas? The documentation project just uses main,
which is no use for Win32 stuff. Also, I think it’s a
little strange that sdl-config --libs doesn’t provide
-lSDLmain for me, I had to put that in myself.

That’s because you shouldn’t link with libSDLmain.a on Linux.

Basicaly I’m after the ‘best practice’:

-Should I call my ‘main’ function main() or
SDL_main()?
-Should I link to libSDLmain.a explicitly?

You should declare your main function like this:
int main(int argc, char *argv[])

You should link with the output of: sdl-config --libs
On systems that need to do things before main runs, SDL will provide
the appropriate initialization code in -lSDLmain and call your main()
function directly.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

After installing a new version of vectorlinux on my
old laptop I have problems compiling SDL_Image,
SDL_Net and more.

The problem is always the same. The ./configure
script quits when checking for SDL >= 1.2.4
Here is the final output of config.log;

/usr/X11R6/lib/libX11.so.6: ‘undefined reference to atexit’

the way the programme is build is;

gcc -o conftest -g -O2 -I/usr/local/include -I/usr/local/
include/SDL -D_REENTRANT conftest.c -L/usr/local/lib
-Wl, -rpath,/usr/local/lib -lSDL -lpthread 1>&5

could it be that sdl-config gives the wrong parameters?

Thanks in advance,
Rob

Thanks for your help guys. My mis-conception about
starting my program with SDL_main() came from the
first tutorial I ever read, and whilst I figured that
sdl-config --libs would only give me the options I
need, I couldn’t figure out why I wouldn’t need to
-lSDLmain! Now I know that #define main SDL_main is
sat there in the source, I feel a lot happier!

Thanks once again for the quick replies… this list
is great!

Paul Smith__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute