SDL_main( .. ) vs. main( .. ) (?)

hi.

after seeing a post the other day about a guy having problems with
SDLmain, i was looking through the SDL_main header and source code for
different platforms. It appears that i should be using SDL_main as my
main method/function instead of my current solution:

#ifdef _WIN32
WinMain (…blah…)
{
int argc;
char *argv[];
// …
// … parse arguments into GNU/linux (POSIX?) format…
// …
#else
main(int argc, char *argv[])
{
#endif

but i found nothing that tells me i should do this. should i? have i
guessed wrong? looking at it… it seems like the way to go. is this
something that should be added to the SDL doc/FAQ? i haven’t found it
written anywhere, apart from in the FAQ where it says:

"You should be using main() instead of WinMain() even though you are
creating a Windows application…"
http://www.libsdl.org/faq.php?action=listentries&category=4#48

and also in all of the SDL Doc project documentation, it implies that i
should be using main… but i was getting problems with reading the
arguments when i was writing my project just using a main(int argc, char
*argv[]) in windows (i’m pretty sure… it was a few months ago
that i i last touched that bit, though), through mingw.

there seems to be something in the SDL main headers something that
defines SDL_main as main or something, which appears might allow for
this, but i didn’t really see how it would work.

ok well… any light anyone can shed on the situation would make me
very happy.

-baggins

[…]

but i found nothing that tells me i should do this. should i? have i
guessed wrong? looking at it… it seems like the way to go. is this
something that should be added to the SDL doc/FAQ? i haven’t found it
written anywhere, apart from in the FAQ where it says:

"You should be using main() instead of WinMain() even though you are
creating a Windows application…"
http://www.libsdl.org/faq.php?action=listentries&category=4#48

and also in all of the SDL Doc project documentation, it implies that i
should be using main… but i was getting problems with reading the
arguments when i was writing my project just using a main(int argc, char
*argv[]) in windows (i’m pretty sure… it was a few months ago
that i i last touched that bit, though), through mingw.

If you look at the contents of the header SDL_main.h, you will find this
line:

#define main SDL_main

If the file which contains main happens to include SDL.h or SDL_main.h, it
will work fine. Now this means you only need SDLmain in Win32 and MacOS,
but if you name the function SDL_main instead you can link the static lib
in any application on any platform. This is what I’ve been suggesting to
everyone who brings this up lately. =)

main should work though, as long as the right header is included.

there seems to be something in the SDL main headers something that
defines SDL_main as main or something, which appears might allow for
this, but i didn’t really see how it would work.

ok well… any light anyone can shed on the situation would make me
very happy.

Let’s try this one out, shall we?

Case #1:
MacOS with SDLmain, your code has main ()

  • The main redefinition in SDL_main.h applies
  • main in your code is redefined SDL_main
  • SDLmain calls SDL_main after initializing QuickDraw

Case #2:
Win32 with SDLmain, your code has SDL_main ()

  • The main redefinition in SDL_main.h applies
  • You don’t have a main to redefine
  • SDLmain calls SDL_main after registering the application with Win32

Case #3:
Linux without SDLmain, your code has main ()

  • SDL_main.h doesn’t apply any redefinitions
  • main just works.

Case #4:
Linux with SDLmain, your code has main ()

  • SDL_main.h doesn’t apply any redefinitions
  • SDLmain.a’s main gets overridden by yours because the linker decides
    your version is the one you want
  • Everything works, but probably this is a bad thing to depend on…

Case #5:
Linux with SDLmain, your code has SDL_main ()

  • SDL_main.h doesn’t apply any redefinitions
  • SDLmain.a’s main calls SDL_main in your code
  • Everything works, and if ever some platform was added which needed
    SDLmain, your code already uses it everywhere. You’re future
    brain-damage proof. =)

Hopefully that explains how it works more?On Sat, May 25, 2002 at 09:17:48AM +0100, William Robinson wrote:


Joseph Carter Certified free software nut

knghtbrd: are you there?
I’m not sure - let me go ask me.
Yeah, I said that I’m here. =)

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020525/495bd572/attachment.pgp

If you look at the contents of the header SDL_main.h, you will find this
line:

#define main SDL_main

i’m not sure whether i trust this for, but… ok. probably getting
off-topic, but can you do this in all c-compilers? and also what’s all
that stuff about C linkage? or do i not really want to get into that?
i’m writing in C++. could this have been my problem when i was
cross-compiling C++ using mingw?

If the file which contains main happens to include SDL.h or SDL_main.h, it
will work fine. Now this means you only need SDLmain in Win32 and MacOS,
but if you name the function SDL_main instead you can link the static lib
in any application on any platform. This is what I’ve been suggesting to
everyone who brings this up lately. =)

main should work though, as long as the right header is included.

there seems to be something in the SDL main headers something that
defines SDL_main as main or something, which appears might allow for
this, but i didn’t really see how it would work.

ok well… any light anyone can shed on the situation would make me
very happy.

Let’s try this one out, shall we?

Case #2:
Win32 with SDLmain, your code has SDL_main ()

  • The main redefinition in SDL_main.h applies
  • You don’t have a main to redefine
  • SDLmain calls SDL_main after registering the application with Win32

so… to get it working on win32 and linux, using the GNU/linux argument
format, i SHOULD ideally use SDL_main as my main method? to be safe? so
this will work transparently on other OSs? ok good. thanks. is this the
opinion of the SDL maintainers also? i guess that was also one of my
questions…

-b

Hi folks,

Im a newbie to SDL, and im trying to get a project ive been working on
with others on linux to compile on project builder. The SDL template
seems to build and execute ok, but whenever I try to add this extra code
i have, which is mostly c++ files, i run into a lot of problems with
linking. The closest i seem to get to a successful build is when i get
this error message:

/usr/bin/ld: warning prebinding disabled because of undefined symbols
/usr/bin/ld: Undefined symbols:
__._8ifstream
___8ifstreamiPCcii
___ls__7ostreamPCc
___ls__7ostreamPFRB0_RB0
___ls__7ostreamUi
___ls__7ostreamb
___ls__7ostreamc
___ls__7ostreami
___rs__7istreamRc
___rs__7istreamRi
_assign__t18string_char_traits1ZcRcRCc
_cerr
_compare__t18string_char_traits1ZcPCcn1Ul
_copy__t18string_char_traits1ZcPcPCcUl
_cout
_endl__FR7ostream
_eos__t18string_char_traits1Zc
_eq__t18string_char_traits1ZcRCcn1
_ipfx0__7istream
_is_del__t18string_char_traits1Zcc
_isfx__7istream
_length__t18string_char_traits1ZcPCc
_move__t18string_char_traits1ZcPcPCcUl
_rdbuf__C3ios
_sbumpc__9streambuf
_set__t18string_char_traits1ZcPcRCcUl
_setstate__3iosi
_sungetc__9streambuf
_width__3iosi
_write__7ostreamPCci
…failed StandaloneExecutable.LinkUsingFileList
/Users/jridenou/p16/build/p16.app/Contents/MacOS/p16 …

Does this look familiar to anyone? Does anyone have a link to a PB
project that works with C++ code?

thanks,

jeff
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 1454 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020525/63287f56/attachment.bin

If you look at the contents of the header SDL_main.h, you will find this
line:

#define main SDL_main

i’m not sure whether i trust this for, but… ok. probably getting
off-topic, but can you do this in all c-compilers? and also what’s all
that stuff about C linkage? or do i not really want to get into that?
i’m writing in C++. could this have been my problem when i was
cross-compiling C++ using mingw?

Yes you can do this in any C/C++ compiler.

But it’s only done on certain platforms currently. I’d like to convince
Sam to recommend SDL_main for all platforms in the future, but I am sure
people will squawk loudly at this. =/

SDL is a C library, not C++, so it needs to extern “C” everything. That’s
what the CLINKAGE stuff is all about.

so… to get it working on win32 and linux, using the GNU/linux argument
format, i SHOULD ideally use SDL_main as my main method? to be safe? so
this will work transparently on other OSs? ok good. thanks. is this the
opinion of the SDL maintainers also? i guess that was also one of my
questions…

Actually, the argument format has nothing to do with POSIX or Linux, it’s
the ANSI C required argument format. It’s not a method (methods are
attached to classes, which are a foriegn concept in the SDL source code
since it’s written in C…) But the SDL_main function is what I suggest
you use because it works everywhere, including places where it isn’t
actually needed.On Sat, May 25, 2002 at 10:25:12AM +0100, William Robinson wrote:


Joseph Carter Sooner or later, BOOM!

Unix is mature OS, windows is still in diapers and they smell badly.
– Rafael Skodlar

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020525/9ddea0bf/attachment.pgp

You aren’t linking to the C++ library. Add libstdc++.a to your project.
It is in /usr/lib/. Since the template is C it doesn’t link to this. Now
that you mention it, it might be a good idea to add it anyway since it
doesn’t hurt anything in C land.

-DOn Saturday, May 25, 2002, at 04:40 AM, Jeff Ridenour wrote:

Hi folks,

Im a newbie to SDL, and im trying to get a project ive been working on
with others on linux to compile on project builder. The SDL template
seems to build and execute ok, but whenever I try to add this extra
code i have, which is mostly c++ files, i run into a lot of problems
with linking. The closest i seem to get to a successful build is when
i get this error message:

/usr/bin/ld: warning prebinding disabled because of undefined symbols
/usr/bin/ld: Undefined symbols:
__._8ifstream
___8ifstreamiPCcii
___ls__7ostreamPCc
___ls__7ostreamPFRB0_RB0
___ls__7ostreamUi
___ls__7ostreamb
___ls__7ostreamc
___ls__7ostreami
___rs__7istreamRc
___rs__7istreamRi
_assign__t18string_char_traits1ZcRcRCc
_cerr
_compare__t18string_char_traits1ZcPCcn1Ul
_copy__t18string_char_traits1ZcPcPCcUl
_cout
_endl__FR7ostream
_eos__t18string_char_traits1Zc
_eq__t18string_char_traits1ZcRCcn1
_ipfx0__7istream
_is_del__t18string_char_traits1Zcc
_isfx__7istream
_length__t18string_char_traits1ZcPCc
_move__t18string_char_traits1ZcPcPCcUl
_rdbuf__C3ios
_sbumpc__9streambuf
_set__t18string_char_traits1ZcPcRCcUl
_setstate__3iosi
_sungetc__9streambuf
_width__3iosi
_write__7ostreamPCci
…failed StandaloneExecutable.LinkUsingFileList
/Users/jridenou/p16/build/p16.app/Contents/MacOS/p16 …

Does this look familiar to anyone? Does anyone have a link to a PB
project that works with C++ code?

thanks,

jeff
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 1793 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020525/4bfafb19/attachment.bin

This worked! thanks a lot, although it would be very helpful if it was
in the template, since it was not easy to get it added to the project.
(project builder / OSX gui doesn’t even let you find the file or usr
directory)

jeffOn Saturday, May 25, 2002, at 06:43 AM, Darrell Walisser wrote:

You aren’t linking to the C++ library. Add libstdc++.a to your project.
It is in /usr/lib/. Since the template is C it doesn’t link to this.
Now that you mention it, it might be a good idea to add it anyway since
it doesn’t hurt anything in C land.

-D

On Saturday, May 25, 2002, at 04:40 AM, Jeff Ridenour wrote:

Hi folks,

Im a newbie to SDL, and im trying to get a project ive been working on
with others on linux to compile on project builder. The SDL template
seems to build and execute ok, but whenever I try to add this extra
code i have, which is mostly c++ files, i run into a lot of problems
with linking. The closest i seem to get to a successful build is when
i get this error message:

/usr/bin/ld: warning prebinding disabled because of undefined symbols
/usr/bin/ld: Undefined symbols:
__._8ifstream
___8ifstreamiPCcii
___ls__7ostreamPCc
___ls__7ostreamPFRB0_RB0
___ls__7ostreamUi
___ls__7ostreamb
___ls__7ostreamc
___ls__7ostreami
___rs__7istreamRc
___rs__7istreamRi
_assign__t18string_char_traits1ZcRcRCc
_cerr
_compare__t18string_char_traits1ZcPCcn1Ul
_copy__t18string_char_traits1ZcPcPCcUl
_cout
_endl__FR7ostream
_eos__t18string_char_traits1Zc
_eq__t18string_char_traits1ZcRCcn1
_ipfx0__7istream
_is_del__t18string_char_traits1Zcc
_isfx__7istream
_length__t18string_char_traits1ZcPCc
_move__t18string_char_traits1ZcPcPCcUl
_rdbuf__C3ios
_sbumpc__9streambuf
_set__t18string_char_traits1ZcPcRCcUl
_setstate__3iosi
_sungetc__9streambuf
_width__3iosi
_write__7ostreamPCci
…failed StandaloneExecutable.LinkUsingFileList
/Users/jridenou/p16/build/p16.app/Contents/MacOS/p16 …

Does this look familiar to anyone? Does anyone have a link to a PB
project that works with C++ code?

thanks,

jeff
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 2111 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020525/202a649d/attachment.bin

Actually it does if you type /usr in the “Go to” text field.

-DOn Saturday, May 25, 2002, at 02:29 PM, Jeff Ridenour wrote:

This worked! thanks a lot, although it would be very helpful if it was
in the template, since it was not easy to get it added to the project.
(project builder / OSX gui doesn’t even let you find the file or usr
directory)

jeff

On Saturday, May 25, 2002, at 06:43 AM, Darrell Walisser wrote:

You aren’t linking to the C++ library. Add libstdc++.a to your
project. It is in /usr/lib/. Since the template is C it doesn’t link
to this. Now that you mention it, it might be a good idea to add it
anyway since it doesn’t hurt anything in C land.

-D

On Saturday, May 25, 2002, at 04:40 AM, Jeff Ridenour wrote:

Hi folks,

Im a newbie to SDL, and im trying to get a project ive been working
on with others on linux to compile on project builder. The SDL
template seems to build and execute ok, but whenever I try to add
this extra code i have, which is mostly c++ files, i run into a lot
of problems with linking. The closest i seem to get to a successful
build is when i get this error message:

/usr/bin/ld: warning prebinding disabled because of undefined symbols
/usr/bin/ld: Undefined symbols:
__._8ifstream
___8ifstreamiPCcii
___ls__7ostreamPCc
___ls__7ostreamPFRB0_RB0
___ls__7ostreamUi
___ls__7ostreamb
___ls__7ostreamc
___ls__7ostreami
___rs__7istreamRc
___rs__7istreamRi
_assign__t18string_char_traits1ZcRcRCc
_cerr
_compare__t18string_char_traits1ZcPCcn1Ul
_copy__t18string_char_traits1ZcPcPCcUl
_cout
_endl__FR7ostream
_eos__t18string_char_traits1Zc
_eq__t18string_char_traits1ZcRCcn1
_ipfx0__7istream
_is_del__t18string_char_traits1Zcc
_isfx__7istream
_length__t18string_char_traits1ZcPCc
_move__t18string_char_traits1ZcPcPCcUl
_rdbuf__C3ios
_sbumpc__9streambuf
_set__t18string_char_traits1ZcPcRCcUl
_setstate__3iosi
_sungetc__9streambuf
_width__3iosi
_write__7ostreamPCci
…failed StandaloneExecutable.LinkUsingFileList
/Users/jridenou/p16/build/p16.app/Contents/MacOS/p16 …

Does this look familiar to anyone? Does anyone have a link to a PB
project that works with C++ code?

thanks,

jeff
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 2262 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020525/547be0bc/attachment.bin