SDL_main

Hi,

I am new with SDL, so the question is perhaps really stupid.
I am working on Win32, and included in my project the SDL.lib and
SDLmain.lib as said in the help of VisualC.html.
But now I have a problem while building my project.
I have the error
SDLmain.lib(SDL_main.obj) : error LNK2001: unresolved external symbol
_SDL_main

What should I do??

Thanks in advance.

Chloe

Hi,

I am new with SDL, so the question is perhaps really stupid.
I am working on Win32, and included in my project the SDL.lib and
SDLmain.lib as said in the help of VisualC.html.
But now I have a problem while building my project.
I have the error
SDLmain.lib(SDL_main.obj) : error LNK2001: unresolved external symbol
_SDL_main

What should I do??

Add the following line to the file containing main():

#include “SDL.h”

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Hello Sam,

Hi,> I am new with SDL, so the question is perhaps really stupid.
I am working on Win32, and included in my project the SDL.lib and
SDLmain.lib as said in the help of VisualC.html.
But now I have a problem while building my project.> I have the error
SDLmain.lib(SDL_main.obj) : error LNK2001: unresolved external symbol
_SDL_main> What should I do??
Add the following line to the file containing main():#include "SDL.h"See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Unfortunately SDL is not only system which redefine main().
For example, I have a lot of troubles using both SDL and WX.
Same situation with Borland C++ Builder.

Is it possible to remove main() redefinition from SDL?–
Best regards,
Alexei mailto:amnikitin at genome.eimb.relarn.ru

Unfortunately SDL is not only system which redefine main().
For example, I have a lot of troubles using both SDL and WX.
Same situation with Borland C++ Builder.

Is it possible to remove main() redefinition from SDL?

Yes, although you need to make sure that your WinMain() calls the
SDL_RegisterApp() function like the code in src/main/win32/SDL_main.c,
or SDL will not be able to open a window.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

Unfortunately SDL is not only system which redefine main().
For example, I have a lot of troubles using both SDL and WX.
Same situation with Borland C++ Builder.

Is it possible to remove main() redefinition from SDL?

Yes, although you need to make sure that your WinMain() calls the
SDL_RegisterApp() function like the code in src/main/win32/SDL_main.c,
or SDL will not be able to open a window.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Shouldn’t it be possible to move that stuff into SDL_Init()?

I’ve been working on a project using SDL under Dev-C++ with a friend of mine, and I’ve been having a lot of trouble getting it to compile; it never even gets to the code we wrote. Whenever I try to compile, I get the error:

\Dev-C++\lib/libSDLmain.a(SDL_main.o.b) C In function console_main': 227 /home/hercules/release/SDL-1.2.4/src/main/SDL_main.c undefined reference toSDL_main’

This confused me a bit, so I checked the source, and sure enough on line 224 (not 227) of SDL_main.c, there is a call to a function called SDL_main which isn’t defined anywhere. The comment indicates it should run my application’s main(), which seems right to me, but it evidentally doesn’t actually work, at least under Dev-C++.

I downloaded the MinGW version of the SDL development libraries and copied the headers and libraries into the Dev-C++ folders as directed in the tutorials for using SDL and Dev-C++, and I set up the compiler/linker options appropriately.

Does anyone know why this is causing an error for me, and what I can do about it?

Chuck Gaulke

IIRC, if you compile the “right” way, a piece of code is passed to all C
code (*.c) such that anything named “main” gets renamed to “SDL_main”.
But you should simply be able to change “main()” to “SDL_main()” and have
everything work.

“Should” being the keyword.

-MarkOn Tue, 7 May 2002, Charles Gaulke wrote:

I’ve been working on a project using SDL under Dev-C++ with a friend of mine, and I’ve been having a lot of trouble getting it to compile; it never even gets to the code we wrote. Whenever I try to compile, I get the error:

\Dev-C++\lib/libSDLmain.a(SDL_main.o.b) C In function console_main': 227 /home/hercules/release/SDL-1.2.4/src/main/SDL_main.c undefined reference toSDL_main’

This confused me a bit, so I checked the source, and sure enough on line 224 (not 227) of SDL_main.c, there is a call to a function called SDL_main which isn’t defined anywhere. The comment indicates it should run my application’s main(), which seems right to me, but it evidentally doesn’t actually work, at least under Dev-C++.

I downloaded the MinGW version of the SDL development libraries and copied the headers and libraries into the Dev-C++ folders as directed in the tutorials for using SDL and Dev-C++, and I set up the compiler/linker options appropriately.

Does anyone know why this is causing an error for me, and what I can do about it?

Chuck Gaulke


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Mark K. Kim
http://www.cbreak.org/
PGP key available upon request.

IIRC, if you compile the “right” way, a piece of code is passed to all C
code (*.c) such that anything named “main” gets renamed to “SDL_main”.
But you should simply be able to change “main()” to “SDL_main()” and have
everything work.

The key is to add the following line to the top of the file with main():

#include “SDL.h”

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

At 23:17 07/05/2002 -0700, you wrote:

IIRC, if you compile the “right” way, a piece of code is passed to all C
code (*.c) such that anything named “main” gets renamed to “SDL_main”.
But you should simply be able to change “main()” to “SDL_main()” and have
everything work.

That was the second or third thing I thought of… If only something that simple could really work.

The key is to add the following line to the top of the file with main():

#include “SDL.h”

That was the thing I checked right before I tried the above… I’ve got the header included, doesn’t help.

I notice that in the code for SDL_main.c, ‘console_main’ gets #defined as ‘main’, but only if the code is being compiled with VC++ (at least, I think so). Could this be in some way related? I don’t know what the MinGW version of the library was compiled with, of course - I’m just sort of grasping at straws here, since it seems like one of the above two suggestions ought to fix my problem.

Chuck

Charles Gaulke wrote:

The key is to add the following line to the top of the file with main():

#include “SDL.h”

That was the thing I checked right before I tried the above… I’ve got the header included, doesn’t help.

I notice that in the code for SDL_main.c, ‘console_main’ gets #defined as ‘main’, but only if the code is being compiled with VC++ (at least, I think so). Could this be in some way related? I don’t know what the MinGW version of the library was compiled with, of course - I’m just sort of grasping at straws here, since it seems like one of the above two suggestions ought to fix my problem.

The other thing is to match the following syntax for main:

int main(int argc, char**argv)

the int and char** types and params are probably what you are missing in your main.–
-==-
Jon Atkins
http://jcatki.2y.net/

At 04:50 09/05/2002 -0500, you wrote:

The other thing is to match the following syntax for main:

int main(int argc, char**argv)

the int and char** types and params are probably what you are missing in your main.

Nope… That’s how my main function was defined to begin with (well, it was char *argv[] instead of char **argv, but that shouldn’t make a difference, should it? I tried changing it just in case, didn’t do anything).

Chuck

#define main SDL_main

Is this really necessary and great idea? It’s causing
me headache when I’m calling stuff from other libraries:

#include “SDL.h”
#include “MyLibrary.h”

myObj.main();

unresolved external symbol “public: void __thiscall MyClass::SDL_main(void)”

Took me a while to figure this one out. (Maybe I’m slow.)

Admittedly, methods named “main” may not be so common. And
there are workarounds. But I still don’t like it.

gtxayf1q001 at sneakemail.com wrote:

#define main SDL_main

Is this really necessary and great idea?

I don’t like it either. Aside from messing up local identifiers, it
also prevents the use of other libraries that also subsume ‘main’, and
it depends on the relevant header file being included in the file that
defines ‘main’. And it is quite unnecessary.

One quick hack that will probably solve your problem: #undef main.
Then call you ‘main’ function ‘SDL_main’ instead.–
Rainer Deyke | root at rainerdeyke.com | http://rainerdeyke.com

This wouldn’t work in environments like Unix that expect the main()
function to be called “main”… :frowning: Too bad there is no construct in the
C preprocessor to temporarily supress a particular macro.

-LorenOn Mon, 2002-09-02 at 17:07, Rainer Deyke wrote:

One quick hack that will probably solve your problem: #undef main.
Then call you ‘main’ function ‘SDL_main’ instead.

Loren Osborn wrote:> On Mon, 2002-09-02 at 17:07, Rainer Deyke wrote:

One quick hack that will probably solve your problem: #undef main.
Then call you ‘main’ function ‘SDL_main’ instead.

This wouldn’t work in environments like Unix that expect the main()
function to be called “main”… :frowning: Too bad there is no construct in
the C preprocessor to temporarily supress a particular macro.

#ifdef main
#undef main
#define my_main SDL_main
#else
#define my_main main
#endif

int my_main()
{
/* code here */
}

This will work on all systems.


Rainer Deyke | root at rainerdeyke.com | http://rainerdeyke.com

One quick hack that will probably solve your problem: #undef main.
Then call you ‘main’ function ‘SDL_main’ instead.

This wouldn’t work in environments like Unix that expect the main()
function to be called “main”… :frowning: Too bad there is no construct in
the C preprocessor to temporarily supress a particular macro.

#ifdef main
#undef main
#define my_main SDL_main
#else
#define my_main main
#endif

int my_main()
{
/* code here */
}

This will work on all systems.

Indeed. But it’s still not perfect. There is no guarantee
that function named SDL_main works the same way in the next
release of SDL. And there is still one unnecessary #define.

The best I could come up with is something like this:

// Begin main_fix
#include "SDL.h"
int my_main(int argc, char *argv[]);
int main(int argc, char *argv[])
{
return my_main(argc, argv);
}
#ifdef main
#undef main
#endif
// End main_fix

-lSDLmain in unix. I do this always for precisely this reason.On Mon, Sep 02, 2002 at 05:19:52PM -0700, Loren Osborn wrote:

One quick hack that will probably solve your problem: #undef main.
Then call you ‘main’ function ‘SDL_main’ instead.

This wouldn’t work in environments like Unix that expect the main()
function to be called “main”… :frowning: Too bad there is no construct in the
C preprocessor to temporarily supress a particular macro.


Joseph Carter This end upside-down

It’s not usually cost effective time wise to go do it. But if something’s
really pissing you off, you just go find the code and fix it and that’s
really cool.
– John Carmack, on the advantages of open source

-------------- 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/20020904/94965693/attachment.pgp

What exactly does SDL do with main, and why is this in the library
in this form?

I’m at a loss to understand why we don’t just have
two functions

SDL_start
SDL_finish

which encapsulate the prolog and epilog code.
[the old method can be provided in a separate header]

My application code lives in a DLL which is loaded
under program control. You can’t fiddle it by macro’ing main.
What am I losing?–
john skaller
@john_skaller
http://felix-lang.org

Sorry, I’m trying to sort out exactly what you are asking.

Are you trying to sort out the relationship of SDL2.dll and SDL2_main.dll ?

If you are trying to load up SDL functionality from a DLL, it would be wise
for your main program to handle SDL_init and SDL_quit, and the DLL just
makes the assumption that this has been done. If that can’t be done, most
applications that I’ve used that use DLL files as plugins typically search
for a startup() and shutdown() functions (with varying naming conventions),
in which case, you could call SDL_init() and SDL_quit() inside those
functions in your DLL file.

Sorry if I’m way off, I’m trying to understand the context of your
question, and having a bit of trouble with that.On Mon, Jun 10, 2013 at 9:37 AM, john skaller <skaller at users.sourceforge.net wrote:

What exactly does SDL do with main, and why is this in the library
in this form?

I’m at a loss to understand why we don’t just have
two functions

    SDL_start
    SDL_finish

which encapsulate the prolog and epilog code.
[the old method can be provided in a separate header]

My application code lives in a DLL which is loaded
under program control. You can’t fiddle it by macro’ing main.
What am I losing?


john skaller
skaller at users.sourceforge.net
http://felix-lang.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL_main exists because some OSes require a special main() entry point for
graphical programs (e.g. WinMain()). SDL_main makes it so that you can
write a single entry point that is cross-platform. It has nothing to do
with initialization of SDL.

Jonny DOn Mon, Jun 10, 2013 at 9:45 AM, Alex Barry <alex.barry at gmail.com> wrote:

Sorry, I’m trying to sort out exactly what you are asking.

Are you trying to sort out the relationship of SDL2.dll and SDL2_main.dll ?

If you are trying to load up SDL functionality from a DLL, it would be
wise for your main program to handle SDL_init and SDL_quit, and the DLL
just makes the assumption that this has been done. If that can’t be done,
most applications that I’ve used that use DLL files as plugins typically
search for a startup() and shutdown() functions (with varying naming
conventions), in which case, you could call SDL_init() and SDL_quit()
inside those functions in your DLL file.

Sorry if I’m way off, I’m trying to understand the context of your
question, and having a bit of trouble with that.

On Mon, Jun 10, 2013 at 9:37 AM, john skaller < skaller at users.sourceforge.net> wrote:

What exactly does SDL do with main, and why is this in the library
in this form?

I’m at a loss to understand why we don’t just have
two functions

    SDL_start
    SDL_finish

which encapsulate the prolog and epilog code.
[the old method can be provided in a separate header]

My application code lives in a DLL which is loaded
under program control. You can’t fiddle it by macro’ing main.
What am I losing?


john skaller
skaller at users.sourceforge.net
http://felix-lang.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org