We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 475

Summary: sdl-config needs a --libs-no-sdlmain option
Product: SDL Reporter: Ryan C. Gordon <icculus>
Component: mainAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 1.2   
Hardware: x86   
OS: Other   

Description Ryan C. Gordon 2007-08-06 16:45:09 UTC
When building SDL_sound, we get the SDL libraries we link to from calling "sdl-config --libs" somwhere in the configure script.

On Mac OS X, where SDLmain exists, this gives us:

   -L/usr/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa

So SDL_sound, the dynamic library, links to SDLmain.

Apps using SDL_sound, such as the included playsound app, link against SDL_sound and SDL and SDLmain.

However, it appears that Mac OS X's dynamic loader is choosing the wrong copy of SDL_main, the end result being that we eventually get to playsound's actual main(), but we ended up writing to the wrong gArgc/gArgv, so we end up getting called with argc==0 and argv==NULL.

And to frustrate things more, gdb looks at the wrong set of symbols when setting breakpoints.  :)

I believe this is new behaviour in Tiger or gcc4...we've probably been linking against SDLmain inadvertently forever on Mac OS X, but the order symbols resolve is different now.

I wouldn't be surprised if SDL_mixer, etc has this same problem, and no one noticed because most people don't use command lines on the Mac and they might just skip cmdline processing when argc==0 in their for-loop. I only noticed because playsound assumes that argv[0] is always valid.

Basically, the solution is not to link libraries against SDLmain, just apps that have real mainlines, but there isn't a way to get this information from sdl-config. Would it be possible to add a --libs_no_sdlmain option to sdl-config?

--ryan.
Comment 1 Ryan C. Gordon 2007-08-06 16:45:40 UTC
(Corrected grammar in Summary.)

--ryan.


Comment 2 Sam Lantinga 2009-10-10 11:47:17 UTC
Debian apparently has a --library-libs option for their sdl-config script.

I couldn't find it in their sources though, so I sent e-mail to the maintainers to see if they could send it to me.
Comment 3 Sam Lantinga 2009-10-17 11:00:35 UTC
No response from the Debian maintainers, I'm closing this for now.

Please re-open this for SDL 1.3 if the Debian maintainers respond.