The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Suggestion/Discussion: is SDL2main a bad idea?
Jonas Thiem
Guest

Hi *,

In the IRC channel freenode/#SDL, a lot of people come by struggling
with getting SDL2 to work due to
http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27SDL_main.27.22_...

Even despite following compiler options, many have trouble getting it to work.

I use SDL 1.2 and SDL 2 for some years myself already, but I still
have one project where this part fails too, and I still haven't
figured out why, just for this particular project (works for all my
others). I worked around it by peeking on SDL_windos_main.c, and then
just manually calling SDL_SetMainReady and ignoring command line
arguments for SDL.

Anyway, really a LOT of people seem to get stuck on this (judging by
newcomers stumbling into IRC with all of them having this issue) even
if they apparently seem to use the correct linker flags, and
apparently all this is for is "magic" command line parsing of SDL
behind the scenes and main everywhere instead of WinMain?

Let me suggest a consideration whether the trouble this feature causes
and the benefit it brings are a good trade.

Was there ever a consideration of having SDL_Init manually take the
command line arguments instead through parameters or something, and
have the windows applications own their regular WinMain themselves?


I guess without all this magic stuff, people would need to use WinMain
or int main on depending on the platform, and the main function of SDL
apps would no longer be platform independent.

But isn't there another way? E.g. a macro that should be used instead
of a main which expands to main or WinMain depending on the platform,
then passing the arguments to SDL_Init explicitely?

Just something that is less of a linker hack. (since it seems to cause
a lot of issues for many newcomers)


Regards,
Jonas Thiem
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Suggestion/Discussion: is SDL2main a bad idea?
Alberto Corona
Guest

On Monday, April 07, 2014 23:10:06 Jonas Thiem wrote:
Quote:
I guess without all this magic stuff, people would need to use WinMain
or int main on depending on the platform, and the main function of SDL
apps would no longer be platform independent.

Exactly, this way people don't have to write platform dependent code,
especially when it's something as trivial as this. It wouldn't make much sense
to have to write an overly verbose WinMain when SDL can already do that for
you.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Nathaniel J Fries


Joined: 30 Mar 2010
Posts: 444
I don't use SDL2_main. I always just #undef main after including SDL.h, and use either WinMain or main depending on whether or not I need to use a console.
but I also don't use command-line arguments, this is not true of many applications using SDL.
mr_tawan


Joined: 13 Jan 2014
Posts: 161
I don't have any problems with SDLmain. Of course it confuses people, but they are supposed to read the document before starting using it, aren't they ?

Anyway I also think that there should be options either to use SDLmain, or normal main function on each platform (WinMain() on Windows). Again having too many options may be conflicted with the library name (*Simple* DirectMedia Layer).
Suggestion/Discussion: is SDL2main a bad idea?
Eric Wing
Guest

On 4/7/14, Jonas Thiem wrote:
Quote:
Hi *,

In the IRC channel freenode/#SDL, a lot of people come by struggling
with getting SDL2 to work due to
http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27SDL_main.27.22_...

Even despite following compiler options, many have trouble getting it to
work.

I use SDL 1.2 and SDL 2 for some years myself already, but I still
have one project where this part fails too, and I still haven't
figured out why, just for this particular project (works for all my
others). I worked around it by peeking on SDL_windos_main.c, and then
just manually calling SDL_SetMainReady and ignoring command line
arguments for SDL.

Anyway, really a LOT of people seem to get stuck on this (judging by
newcomers stumbling into IRC with all of them having this issue) even
if they apparently seem to use the correct linker flags, and
apparently all this is for is "magic" command line parsing of SDL
behind the scenes and main everywhere instead of WinMain?

Let me suggest a consideration whether the trouble this feature causes
and the benefit it brings are a good trade.

Was there ever a consideration of having SDL_Init manually take the
command line arguments instead through parameters or something, and
have the windows applications own their regular WinMain themselves?


I guess without all this magic stuff, people would need to use WinMain
or int main on depending on the platform, and the main function of SDL
apps would no longer be platform independent.

But isn't there another way? E.g. a macro that should be used instead
of a main which expands to main or WinMain depending on the platform,
then passing the arguments to SDL_Init explicitely?

Just something that is less of a linker hack. (since it seems to cause
a lot of issues for many newcomers)



I also have many reservations about SDLMain. There two things that
concern me about it:
1. When I build a library that uses SDL instead of an application, I'm
worried about potential duplicate symbol problems.
2. For cross-platform build systems, some platforms need to explicitly
link to an SDLMain library while others don't. (This surprisingly
little difference caused me lots of headaches in the SDL 1.2 era. And
I know it causes a lot of other people headaches too since I got
contacted a lot about it.)

I mentioned I'm working on an proposal in another thread that tries to
use SDL as an embeddable library (instead of a framework that takes
control of the event loop). I've seen an instance where I was worried
SDLMain would give me problems with linkage (#1), but so far it
actually has not. However, the build process for Visual Studio linkage
(#2) has started annoying me.

Unfortunately, I still don't feel quite far enough along in my
experiments to have a solid proposal (if any) for this. I was quietly
thinking of the macro idea too, but I haven't thought it through yet.
I've needed to reshuffle my experiment priorities a bit. I'm still
working with SDL, but on some other things, so it may be another few
weeks.

Thanks,
Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Suggestion/Discussion: is SDL2main a bad idea?
Luke Groeninger
Guest

From my recent experiences, especially with SDL and Visual Studio, I can both appreciate the purpose of SDLmain and understand the frustrations people are having with it.

That said. Is this actually an issue with SDLmain being poorly designed, or simply poorly documented?

Outside of duplicate symbol problems (how big of an issue is this?) it seems that the biggest problem is that there is very little transparency on how/when it has to be used - especially since it occupies kind of an awkward place of being optional on some platforms/build environments and required in others.

Does it actually need to be reengineered, or just better documented?

-Luke


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
mattbentley


Joined: 07 Jul 2013
Posts: 72
My personal viewpoint, coming from a mingw/codelite area, is that your code should be compiler-independent where humanly possible. PARTICULARLY when writing libraries.
So not having WinMain is a massive bonus for cross-platform code.
Suggestion/Discussion: is SDL2main a bad idea?
LordHavoc


Joined: 05 Feb 2014
Posts: 23
Location: USA
Have we considered making an SDL_main.h that one just includes into their "main" c file that magically eliminates the need for libSDLmain.a? Obviously it has to be a bit different on OSX where the
main code has to be Objective-C (and we already have a .m file to add to your project for that purpose), but I think you see where I'm going with this.

On 04/08/2014 04:32 PM, mattbentley wrote:
Quote:
My personal viewpoint, coming from a mingw/codelite area, is that your code should be compiler-independent where humanly possible. PARTICULARLY when writing libraries.
So not having WinMain is a massive bonus for cross-platform code.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Suggestion/Discussion: is SDL2main a bad idea?
Alex Szpakowski
Guest

SDL 2 for OS X doesn’t use an SDLmain.m (whereas SDL 1 does.)

On Apr 8, 2014, at 9:15 PM, Forest Hale wrote:

Quote:
Have we considered making an SDL_main.h that one just includes into their "main" c file that magically eliminates the need for libSDLmain.a? Obviously it has to be a bit different on OSX where the
main code has to be Objective-C (and we already have a .m file to add to your project for that purpose), but I think you see where I'm going with this.

--
LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Nathaniel J Fries


Joined: 30 Mar 2010
Posts: 444
Eric Wing wrote:
1. When I build a library that uses SDL instead of an application, I'm
worried about potential duplicate symbol problems.

libraries should not link to SDL[2]main, unless the library needs to further abstract application structure (such as, maybe, a game engine that only uses SDL on some platforms).

Eric Wing wrote:
2. For cross-platform build systems, some platforms need to explicitly
link to an SDLMain library while others don't. (This surprisingly
little difference caused me lots of headaches in the SDL 1.2 era. And
I know it causes a lot of other people headaches too since I got
contacted a lot about it.)

this should be documented. I'll admit to not knowing whether it is or not.