
Hi. I am using Windows Vista. I installed the following: - ghc 6.8.3 (using official Windows binary installer) - MinGW (from http://nuwen.net/mingw.html) - SDL binding (from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL) I am trying to compile the following program: module Main where import qualified Graphics.UI.SDL as SDL main = do SDL.init [SDL.InitEverything] SDL.quit I get the following error: C:\Users\client\code\sandbox>ghc --make Example.hs Linking Example.exe ... C:\MinGW\lib/libSDLmain.a(SDL_win32_main.o)(.text+0x409):SDL_win32_main.c: undefined reference to `SDL_main' According to SDL faq (http://www.libsdl.org/faq.php?action=listentries&category=4#48) I should use "int main(int argc, char *argv[])", not "int main()" nor "WinMain()". Can anyone compile the above snippet on windows machine? I am using SDL library that is shipped with MinGW distribution that I'm using. I also recompiled SDL haskell binding with official SDL windows binary (http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz). But I get the same undefined reference to SDL_main linker error. Do I need to have specific main IO action so that SDL would work in Haskell? Thank you. Sam.

From the link you provided (http://www.libsdl.org/faq.php?action=listentries&category=4#48)
Q: I get "Undefined reference to 'SDL_main'" ... A: Make sure that you are declaring main() as:
#include "SDL.h"
int main(int argc, char *argv[])
In particular notice that they want you to include SDL.h. I suspect they are doing something scary like
#define main(ac, av) SDL_Main(ac, av, maybe some other args)
The problem is that the library itself is defining WinMain, so you've
got a fight between the Haskell compiler (which wants to define the
entry point for your program to start up the runtime), and the SDL
library (which is trying to be "helpful" and failing).
I think the binding needs to not include SDLMain and instead do the
initialization itself; see the rest of that FAQ question.
In fact, the "MACOSX" readme file in the Haskell SDL binding talks
about exactly this problem.
-- ryan
On Sat, Dec 6, 2008 at 2:05 PM, sam lee
Hi.
I am using Windows Vista. I installed the following:
- ghc 6.8.3 (using official Windows binary installer) - MinGW (from http://nuwen.net/mingw.html) - SDL binding (from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL)
I am trying to compile the following program:
module Main where
import qualified Graphics.UI.SDL as SDL
main = do SDL.init [SDL.InitEverything] SDL.quit
I get the following error:
C:\Users\client\code\sandbox>ghc --make Example.hs Linking Example.exe ... C:\MinGW\lib/libSDLmain.a(SDL_win32_main.o)(.text+0x409):SDL_win32_main.c: undefined reference to `SDL_main'
According to SDL faq (http://www.libsdl.org/faq.php?action=listentries&category=4#48) I should use "int main(int argc, char *argv[])", not "int main()" nor "WinMain()".
Can anyone compile the above snippet on windows machine? I am using SDL library that is shipped with MinGW distribution that I'm using. I also recompiled SDL haskell binding with official SDL windows binary (http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz). But I get the same undefined reference to SDL_main linker error.
Do I need to have specific main IO action so that SDL would work in Haskell?
Thank you. Sam. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I can compile http://darcs.haskell.org/~lemmih/hsSDL/hssdl/Examples/MacOSX/Test.hs But I can't find the "small Cabal file" and c_main.c . Does anyone have those files? I want to try if Test.hs links well on windows platform.
I think the binding needs to not include SDLMain and instead do the initialization itself; see the rest of that FAQ question.
I can't grep for SDLMain in the binding. How should I modify the
binding code to use WinMain + proper initialization?
Thanks.
Sam.
On Sat, Dec 6, 2008 at 5:19 PM, Ryan Ingram
From the link you provided (http://www.libsdl.org/faq.php?action=listentries&category=4#48)
Q: I get "Undefined reference to 'SDL_main'" ... A: Make sure that you are declaring main() as:
#include "SDL.h"
int main(int argc, char *argv[])
In particular notice that they want you to include SDL.h. I suspect they are doing something scary like
#define main(ac, av) SDL_Main(ac, av, maybe some other args)
The problem is that the library itself is defining WinMain, so you've got a fight between the Haskell compiler (which wants to define the entry point for your program to start up the runtime), and the SDL library (which is trying to be "helpful" and failing).
I think the binding needs to not include SDLMain and instead do the initialization itself; see the rest of that FAQ question.
In fact, the "MACOSX" readme file in the Haskell SDL binding talks about exactly this problem.
-- ryan
On Sat, Dec 6, 2008 at 2:05 PM, sam lee
wrote: Hi.
I am using Windows Vista. I installed the following:
- ghc 6.8.3 (using official Windows binary installer) - MinGW (from http://nuwen.net/mingw.html) - SDL binding (from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL)
I am trying to compile the following program:
module Main where
import qualified Graphics.UI.SDL as SDL
main = do SDL.init [SDL.InitEverything] SDL.quit
I get the following error:
C:\Users\client\code\sandbox>ghc --make Example.hs Linking Example.exe ... C:\MinGW\lib/libSDLmain.a(SDL_win32_main.o)(.text+0x409):SDL_win32_main.c: undefined reference to `SDL_main'
According to SDL faq (http://www.libsdl.org/faq.php?action=listentries&category=4#48) I should use "int main(int argc, char *argv[])", not "int main()" nor "WinMain()".
Can anyone compile the above snippet on windows machine? I am using SDL library that is shipped with MinGW distribution that I'm using. I also recompiled SDL haskell binding with official SDL windows binary (http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz). But I get the same undefined reference to SDL_main linker error.
Do I need to have specific main IO action so that SDL would work in Haskell?
Thank you. Sam. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Did you follow the instructions described in the WIN32 file?
On Sat, Dec 6, 2008 at 2:05 PM, sam lee
Hi.
I am using Windows Vista. I installed the following:
- ghc 6.8.3 (using official Windows binary installer) - MinGW (from http://nuwen.net/mingw.html) - SDL binding (from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL)
I am trying to compile the following program:
module Main where
import qualified Graphics.UI.SDL as SDL
main = do SDL.init [SDL.InitEverything] SDL.quit
I get the following error:
C:\Users\client\code\sandbox>ghc --make Example.hs Linking Example.exe ... C:\MinGW\lib/libSDLmain.a(SDL_win32_main.o)(.text+0x409):SDL_win32_main.c: undefined reference to `SDL_main'
According to SDL faq (http://www.libsdl.org/faq.php?action=listentries&category=4#48) I should use "int main(int argc, char *argv[])", not "int main()" nor "WinMain()".
Can anyone compile the above snippet on windows machine? I am using SDL library that is shipped with MinGW distribution that I'm using. I also recompiled SDL haskell binding with official SDL windows binary (http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz). But I get the same undefined reference to SDL_main linker error.
Do I need to have specific main IO action so that SDL would work in Haskell?
Thank you. Sam. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Yes, with some modifications.
I used SDL-1.2.13, not SDL-1.2.12.
Also, my Include-Dirs has include\SDL, not include:
C:\Users\client\code\SDL-1.2.13\include\SDL
If I don't put include\SDL, I get errors like
Graphics\UI\SDL\General.hsc:1:17: SDL.h: No such file or directory
And I used the following command to configure:
C:\Users\client\Downloads\SDL-0.5.4>runghc Setup.lhs configure
--prefix=C:\Users\client\haskell --datadir=$prefix\share --user
it builds and installs fine. I only get linker error (undefined
reference to SDL_main) when I compile a program that uses SDL binding.
On Sun, Dec 7, 2008 at 4:23 AM, Bit Connor
Did you follow the instructions described in the WIN32 file?
On Sat, Dec 6, 2008 at 2:05 PM, sam lee
wrote: Hi.
I am using Windows Vista. I installed the following:
- ghc 6.8.3 (using official Windows binary installer) - MinGW (from http://nuwen.net/mingw.html) - SDL binding (from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL)
I am trying to compile the following program:
module Main where
import qualified Graphics.UI.SDL as SDL
main = do SDL.init [SDL.InitEverything] SDL.quit
I get the following error:
C:\Users\client\code\sandbox>ghc --make Example.hs Linking Example.exe ... C:\MinGW\lib/libSDLmain.a(SDL_win32_main.o)(.text+0x409):SDL_win32_main.c: undefined reference to `SDL_main'
According to SDL faq (http://www.libsdl.org/faq.php?action=listentries&category=4#48) I should use "int main(int argc, char *argv[])", not "int main()" nor "WinMain()".
Can anyone compile the above snippet on windows machine? I am using SDL library that is shipped with MinGW distribution that I'm using. I also recompiled SDL haskell binding with official SDL windows binary (http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz). But I get the same undefined reference to SDL_main linker error.
Do I need to have specific main IO action so that SDL would work in Haskell?
Thank you. Sam. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Bit Connor
-
Ryan Ingram
-
sam lee