How do i compile an sdl .c file? what are the parameters for mingw32 (DevC++)

Hi all.

I’m new at this group. I have a little experience with opengl and want to
learn sdl.
I want to compile the first program in the doc page but i dont know what to
do. I used the parameter -lsdl but still have this error by DevC++:
[Linker error] undefined reference to `WinMain at 16’

did i forget something? i didnt see anywhere how to compile with mingw32 but
guessed that -lsdl would work. are there any other parameters to be used?

thanks–
http://www.cprogramlama.com.tr.tc

Hello Eren,

Wednesday, March 1, 2006, 1:03:27 PM, you wrote:

EE> Hi all.

EE> I’m new at this group. I have a little experience with opengl and want to
EE> learn sdl.
EE> I want to compile the first program in the doc page but i dont know what to
EE> do. I used the parameter -lsdl but still have this error by DevC++:
EE> [Linker error] undefined reference to `WinMain at 16’

EE> did i forget something? i didnt see anywhere how to compile with mingw32 but
EE> guessed that -lsdl would work. are there any other parameters to be used?

Also do -lsdlmain–
Best regards,
Peter mailto:@Peter_Mulholland

thanks but nothing changed yet. i changed compiler settings to use the
parameters: -lsdl -lsdlmain but i got the same error.

2006/3/1, Peter Mulholland :>

Hello Eren,

Wednesday, March 1, 2006, 1:03:27 PM, you wrote:

EE> Hi all.

EE> I’m new at this group. I have a little experience with opengl and want
to
EE> learn sdl.
EE> I want to compile the first program in the doc page but i dont know
what to
EE> do. I used the parameter -lsdl but still have this error by DevC++:
EE> [Linker error] undefined reference to `WinMain at 16’

EE> did i forget something? i didnt see anywhere how to compile with
mingw32 but
EE> guessed that -lsdl would work. are there any other parameters to be
used?

Also do -lsdlmain


Best regards,
Peter mailto:darkmatter at freeuk.com


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


http://www.cprogramlama.com.tr.tc

thanks but nothing changed yet. i changed compiler settings to use the
parameters: -lsdl -lsdlmain but i got the same error.

gcc -o test test.c sdl-config --cflags --libs

Note the backticks, which run the sdl-config command and use the output.

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

thanks for the reply.
it worked with linux but it didnt with windows 98. the errors from devc++ :

cc1.exe C:\EREN\SDL\cc1.exe unrecognized option -fcflags' cc1.exe C:\EREN\SDL\cc1.exe unrecognized option-flibs`

also the sdl-config command cant be found for running in command line.
the file i386-mingw32msvc-sdl-config is in devc++'s bin directory. ( i
couldnt find any other file with the name sdl-config ) what should i do for
this?

2006/3/1, Sam Lantinga :>

thanks but nothing changed yet. i changed compiler settings to use the
parameters: -lsdl -lsdlmain but i got the same error.

gcc -o test test.c sdl-config --cflags --libs

Note the backticks, which run the sdl-config command and use the output.

    -Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

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


http://www.cprogramlama.com.tr.tc

Hello Eren,

Friday, March 3, 2006, 7:25:43 AM, you wrote:

EE> thanks for the reply.
EE> it worked with linux but it didnt with windows 98. the errors from devc++ :

EE> cc1.exe C:\EREN\SDL\cc1.exe unrecognized option -fcflags' EE> cc1.exe C:\EREN\SDL\cc1.exe unrecognized option-flibs`

EE> also the sdl-config command cant be found for running in command line.
EE> the file i386-mingw32msvc-sdl-config is in devc++'s bin directory. ( i
EE> couldnt find any other file with the name sdl-config ) what should i do for
EE> this?

If you’re using mingw chances are you won’t have the use of the
sdl-config script. Backticks only work under sh-style shells.

Just specifying -lsdl and -lsdlmain should work. At a guess, your
library path isn’t set up correctly, but then I don’t really know much
about mingw.

Any reason to use mingw and not the free MSVC compiler?–
Best regards,
Peter mailto:@Peter_Mulholland

i still get the error
[Linker error] undefined reference to `WinMain at 16’
with -lsdl and -lsdlmain parameters.
the library path may be the reason but i ve copied the .a files in the lib
directory to the lib directory of devc++. (also the include files and bin
files to the same named folders). is there a problem about that?

2006/3/3, Peter Mulholland :>

Hello Eren,

Friday, March 3, 2006, 7:25:43 AM, you wrote:

EE> thanks for the reply.
EE> it worked with linux but it didnt with windows 98. the errors from
devc++ :

EE> cc1.exe C:\EREN\SDL\cc1.exe unrecognized option -fcflags' EE> cc1.exe C:\EREN\SDL\cc1.exe unrecognized option-flibs`

EE> also the sdl-config command cant be found for running in command
line.
EE> the file i386-mingw32msvc-sdl-config is in devc++'s bin directory. ( i
EE> couldnt find any other file with the name sdl-config ) what should i
do for
EE> this?

If you’re using mingw chances are you won’t have the use of the
sdl-config script. Backticks only work under sh-style shells.

Just specifying -lsdl and -lsdlmain should work. At a guess, your
library path isn’t set up correctly, but then I don’t really know much
about mingw.

Any reason to use mingw and not the free MSVC compiler?


Best regards,
Peter mailto:darkmatter at freeuk.com


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


http://www.cprogramlama.com.tr.tc

i found this somewhere

compiler parameters > -lsdl -lsdlmain
linker parameter > -Xlinker

i got no errors but interestingly no exe file was created after compilation.

going on searching. ill inform you if i find sth. else.

2006/3/3, Eren Ezg? <@Eren_Ezgu>:>

i still get the error
[Linker error] undefined reference to `WinMain at 16’
with -lsdl and -lsdlmain parameters.
the library path may be the reason but i ve copied the .a files in the lib
directory to the lib directory of devc++. (also the include files and bin
files to the same named folders). is there a problem about that?

2006/3/3, Peter Mulholland :

Hello Eren,

Friday, March 3, 2006, 7:25:43 AM, you wrote:

EE> thanks for the reply.
EE> it worked with linux but it didnt with windows 98. the errors from
devc++ :

EE> cc1.exe C:\EREN\SDL\cc1.exe unrecognized option -fcflags' EE> cc1.exe C:\EREN\SDL\cc1.exe unrecognized option-flibs`

EE> also the sdl-config command cant be found for running in command
line.
EE> the file i386-mingw32msvc-sdl-config is in devc++'s bin directory. (
i
EE> couldnt find any other file with the name sdl-config ) what should i
do for
EE> this?

If you’re using mingw chances are you won’t have the use of the
sdl-config script. Backticks only work under sh-style shells.

Just specifying -lsdl and -lsdlmain should work. At a guess, your
library path isn’t set up correctly, but then I don’t really know much
about mingw.

Any reason to use mingw and not the free MSVC compiler?


Best regards,
Peter mailto:darkmatter at freeuk.com


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


http://www.cprogramlama.com.tr.tc


http://www.cprogramlama.com.tr.tc

Try

-Dmain=SDL_mainOn Sat, 2006-03-04 at 10:04 +0200, Eren Ezg? wrote:

i found this somewhere

compiler parameters > -lsdl -lsdlmain
linker parameter > -Xlinker

i got no errors but interestingly no exe file was created after
compilation.
going on searching. ill inform you if i find sth. else.


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net

what for shall i use the -Dmain=SDL_main parameter? for compiler or linker.
in fact i tried both but theres no change. the output:

[Linker error] undefined reference to `WinMain at 16’
ld returned 1 exit status

2006/3/4, skaller :>

On Sat, 2006-03-04 at 10:04 +0200, Eren Ezg? wrote:

i found this somewhere

compiler parameters > -lsdl -lsdlmain
linker parameter > -Xlinker

i got no errors but interestingly no exe file was created after
compilation.
going on searching. ill inform you if i find sth. else.

Try

-Dmain=SDL_main


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net


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


http://www.cprogramlama.com.tr.tc

Hello Eren,

Saturday, March 4, 2006, 6:47:49 PM, you wrote:

EE> what for shall i use the -Dmain=SDL_main parameter? for compiler or linker.
EE> in fact i tried both but theres no change. the output:

EE> [Linker error] undefined reference to `WinMain at 16’
EE> ld returned 1 exit status

Retargeting main that way is wrong, and won’t fix the problem anyway.

Did you build SDL yourself or are you using the precompiled Win32
version?

If you have built it yourself, it sounds like it didn’t realise that
you were building with mingw, and compiled it as a *nix version where
the entry point is main(). For Windows apps, the entry point is
WinMain() and libSDLmain.a should know that.–
Best regards,
Peter mailto:@Peter_Mulholland

Hello skaller,

s> you could try just leaving -lsldmain out completely,
s> it doesn’t seem to do anything, that seems to work with
s> both mingw and MSVC++.

You are not initialising your app properly if you are not using
SDLmain, in any compiler.

Check src/main/win32/SDL_win32_main.c to see this for win32.–
Best regards,
Peter mailto:@Peter_Mulholland

you could try just leaving -lsldmain out completely,
it doesn’t seem to do anything, that seems to work with
both mingw and MSVC++.On Sat, 2006-03-04 at 20:47 +0200, Eren Ezg? wrote:

what for shall i use the -Dmain=SDL_main parameter? for compiler or
linker. in fact i tried both but theres no change. the output:

[Linker error] undefined reference to `WinMain at 16’
ld returned 1 exit status


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net

Hello skaller,

Hi Peter …

s> you could try just leaving -lsldmain out completely,
s> it doesn’t seem to do anything, that seems to work with
s> both mingw and MSVC++.

You are not initialising your app properly if you are not using
SDLmain, in any compiler.

Check src/main/win32/SDL_win32_main.c to see this for win32.

I have. Nothing it does there seems important, my test
apps all work fine without SDLmain on Linux and Win32.

Replacing main doesn’t work. My code is in a DLL :)On Sat, 2006-03-04 at 23:14 +0000, Peter Mulholland wrote:


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net

I have. Nothing it does there seems important, my test
apps all work fine without SDLmain on Linux and Win32.

Yep, just don’t try using DirectInput on Windows 98. :slight_smile:

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello skaller,

Sunday, March 5, 2006, 2:00:28 AM, you wrote:

s> I have. Nothing it does there seems important, my test
s> apps all work fine without SDLmain on Linux and Win32.

s> Replacing main doesn’t work. My code is in a DLL :slight_smile:

That’s fine, just don’t expect your code to work on every platform.

You will break on BeOS, MacOS, and if your user tries to use
DirectInput, you will break on Windows too (note the
SDL_SetModuleHandle(GetModuleHandle(NULL)) in the win32 startup).

If you understand these risks and accept them, I guess it’s fine, but
you shouldn’t tell new users trying to get started with the library to
bypass this.–
Best regards,
Peter mailto:@Peter_Mulholland

s> Replacing main doesn’t work. My code is in a DLL :slight_smile:
That’s fine, just don’t expect your code to work on every platform.

It isn’t my code, but code written by clients of my system.
At the moment, except as examples to others, I’m not
writing SDL apps – I’m trying to build bindings to the SDL library,
and organise that if SDL is installed on your computer …
it ‘just works’ with Felix, out of the box, on any platform.

BTW: I do plan to use SDL to write games, but I want to
make some decent ones and that just can’t be done in weak
languages like C. So I’ve developed a whole new programming
language, just to write games with! :slight_smile:

You will break on BeOS, MacOS, and if your user tries to use
DirectInput, you will break on Windows too (note the
SDL_SetModuleHandle(GetModuleHandle(NULL)) in the win32 startup).

Noted. That one is a bug! MSDN says:

“If this parameter is NULL, GetModuleHandle returns a handle to the file
used to create the calling process (.exe file).”

Which means there is no reason not to make that call in SDL_init.
Or even any time you need the module handle.

If you understand these risks and accept them, I guess it’s fine, but
you shouldn’t tell new users trying to get started with the library to
bypass this.

I agree. Instead I asked Sam if it were possible
to fix this problem in SDL 1.3. It’s a pain for many people,
newbies and others alike.

Since main only gets called once, it is usually
possible to replace that hack with

T *x = SDL_statup(argc, argv);
// mainline code here
SDL_finish(x);

where the code in SDL_startup and SDL_finish is exactly
what SDL’s main does now – startup does what would be
done just before SDL_main() is called, and SDL_finish(x)
is done after SDL_main() is called, and T is some struct
containing any state that would otherwise have been
preserved on the stack.

The ONLY thing you cannot do this way is something demanding
the stack such as setjmp/longjmp and I wouldn’t allow
one of them on top of my mainline anyhow.

If this were done, there would be two ways to use SDL:
the simple way, with main replacement, and the slightly
harder way, using SDL_startup/SDL_finish.

Frankly, I’d scrub the “simpler” way because it’s seriously non-portable
and hard to support, and is actually harder for newbies
to use, since it requires arcane knowledge of linker
and compiler switches, and/or sdl-config to be present
and work correctly. In other words, its actually harder
to use than the startup/finish paradigm, which is more
general and better engineering.

Well I don’t expect anyone to break compatibility
by srubbing the existing main replacement paradigm!
Please provide the startup/finish paradigm as well!
The former is easily defined given the latter,
but not vice versa.

It’s quite clear looking at the main code and comments
this is intended anyhow: comments indicate code has
been migrated out into SDL_init.

I’m just hoping this will be done in SDL 1.3.
Without it, embeddding – which most if not all language
bindings need – will be much more difficult. Whoever
maintains the Ocaml, Python, Perl … or Felix bindings
has to do a lot less work with the startup/finish paradigm
than a main replacement paradigm for the simple reason
the latter is unusable. You really don’t think Perl
or Python would defer to SDL and allow it to replace
its mainline? They too will require any startup/finish
code to be called from dynamically loaded shared libraries,
as does Felix.On Sun, 2006-03-05 at 01:03 +0000, Peter Mulholland wrote:


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net

i havent compiled it my own. i just downloaded the binary for windows and
copied the bin,include and lib files to the same directories in Devc++. .
ive tried for both win98 and winxp and the errors are the same.
anyway if i cant success compiling ill go on using opengl.

a question: can u create 3d aplications with sdl?

2006/3/5, skaller :>

On Sun, 2006-03-05 at 01:03 +0000, Peter Mulholland wrote:

s> Replacing main doesn’t work. My code is in a DLL :slight_smile:
That’s fine, just don’t expect your code to work on every platform.

It isn’t my code, but code written by clients of my system.
At the moment, except as examples to others, I’m not
writing SDL apps – I’m trying to build bindings to the SDL library,
and organise that if SDL is installed on your computer …
it ‘just works’ with Felix, out of the box, on any platform.

BTW: I do plan to use SDL to write games, but I want to
make some decent ones and that just can’t be done in weak
languages like C. So I’ve developed a whole new programming
language, just to write games with! :slight_smile:

You will break on BeOS, MacOS, and if your user tries to use
DirectInput, you will break on Windows too (note the
SDL_SetModuleHandle(GetModuleHandle(NULL)) in the win32 startup).

Noted. That one is a bug! MSDN says:

“If this parameter is NULL, GetModuleHandle returns a handle to the file
used to create the calling process (.exe file).”

Which means there is no reason not to make that call in SDL_init.
Or even any time you need the module handle.

If you understand these risks and accept them, I guess it’s fine, but
you shouldn’t tell new users trying to get started with the library to
bypass this.

I agree. Instead I asked Sam if it were possible
to fix this problem in SDL 1.3. It’s a pain for many people,
newbies and others alike.

Since main only gets called once, it is usually
possible to replace that hack with

    T *x = SDL_statup(argc, argv);
    // mainline code here
    SDL_finish(x);

where the code in SDL_startup and SDL_finish is exactly
what SDL’s main does now – startup does what would be
done just before SDL_main() is called, and SDL_finish(x)
is done after SDL_main() is called, and T is some struct
containing any state that would otherwise have been
preserved on the stack.

The ONLY thing you cannot do this way is something demanding
the stack such as setjmp/longjmp and I wouldn’t allow
one of them on top of my mainline anyhow.

If this were done, there would be two ways to use SDL:
the simple way, with main replacement, and the slightly
harder way, using SDL_startup/SDL_finish.

Frankly, I’d scrub the “simpler” way because it’s seriously non-portable
and hard to support, and is actually harder for newbies
to use, since it requires arcane knowledge of linker
and compiler switches, and/or sdl-config to be present
and work correctly. In other words, its actually harder
to use than the startup/finish paradigm, which is more
general and better engineering.

Well I don’t expect anyone to break compatibility
by srubbing the existing main replacement paradigm!
Please provide the startup/finish paradigm as well!
The former is easily defined given the latter,
but not vice versa.

It’s quite clear looking at the main code and comments
this is intended anyhow: comments indicate code has
been migrated out into SDL_init.

I’m just hoping this will be done in SDL 1.3.
Without it, embeddding – which most if not all language
bindings need – will be much more difficult. Whoever
maintains the Ocaml, Python, Perl … or Felix bindings
has to do a lot less work with the startup/finish paradigm
than a main replacement paradigm for the simple reason
the latter is unusable. You really don’t think Perl
or Python would defer to SDL and allow it to replace
its mainline? They too will require any startup/finish
code to be called from dynamically loaded shared libraries,
as does Felix.


John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net


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


http://www.cprogramlama.com.tr.tc

Hello Eren,

Sunday, March 5, 2006, 9:33:47 AM, you wrote:

EE> i havent compiled it my own. i just downloaded the binary for windows and
EE> copied the bin,include and lib files to the same directories in Devc++. .

Hmm… that should work then. Specifying -lSDL and -lSDLmain is right.
If you wanted to use the SDL DLL, it’d be -lSDL.dll and -lSDLmain.

Personally, if this is your first time developing C/C++ and you’re on
Windows, I wouldn’t recommend mingw/DevC++ these days. It’s based on GCC,
and GCC was written with Unix in mind. Windows isn’t Unix, so there’s a
lot of hackery going on inside mingw to make things work.

Microsoft now have Visual C++ Express available for free download, and
this will work fine with SDL. You will also be using the same IDE and
tools that is the de-facto standard in the game development world:

http://msdn.microsoft.com/vstudio/express/visualc

EE> ive tried for both win98 and winxp and the errors are the same.

This wouldn’t make any difference anyway.

EE> anyway if i cant success compiling ill go on using opengl.

OpenGL will get you graphics and that’s it. You will then have to find
a solution for input handling, GL context setup, and sound, if making
a game is what you’re after.

EE> a question: can u create 3d aplications with sdl?

Yes - it does OpenGL context setup (the platform-specific part of OpenGL) for
you.–
Best regards,
Peter mailto:@Peter_Mulholland

thanks for replying. ill try it.

2006/3/5, Peter Mulholland :>

Hello Eren,

Sunday, March 5, 2006, 9:33:47 AM, you wrote:

EE> i havent compiled it my own. i just downloaded the binary for windows
and
EE> copied the bin,include and lib files to the same directories in
Devc++. .

Hmm… that should work then. Specifying -lSDL and -lSDLmain is right.
If you wanted to use the SDL DLL, it’d be -lSDL.dll and -lSDLmain.

Personally, if this is your first time developing C/C++ and you’re on
Windows, I wouldn’t recommend mingw/DevC++ these days. It’s based on GCC,
and GCC was written with Unix in mind. Windows isn’t Unix, so there’s a
lot of hackery going on inside mingw to make things work.

Microsoft now have Visual C++ Express available for free download, and
this will work fine with SDL. You will also be using the same IDE and
tools that is the de-facto standard in the game development world:

http://msdn.microsoft.com/vstudio/express/visualc

EE> ive tried for both win98 and winxp and the errors are the same.

This wouldn’t make any difference anyway.

EE> anyway if i cant success compiling ill go on using opengl.

OpenGL will get you graphics and that’s it. You will then have to find
a solution for input handling, GL context setup, and sound, if making
a game is what you’re after.

EE> a question: can u create 3d aplications with sdl?

Yes - it does OpenGL context setup (the platform-specific part of OpenGL)
for
you.


Best regards,
Peter mailto:darkmatter at freeuk.com


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


http://www.cprogramlama.com.tr.tc