我试图在OSX 10.8.2,SDL 1.2.15,GHC 7.4.2,haskell SDL绑定0.6.4上编译并运行一个简单的SDL程序:
import Graphics.UI.SDL as SDL
main :: IO ()
main = do
screen <- setVideoMode 640 480 32 [SWSurface]
hello <- loadBMP "hello.bmp"
blitSurface hello Nothing screen Nothing
SDL.flip screen
delay 2000
它编译(ghc test.hs
)没有错误,但是当我尝试运行它时,我得到以下异常:
$ ./test
2012-11-30 12:37:29.453 test[8995:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8cf060a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff88e813f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8cf05e7c +[NSException raise:format:] + 204
3 AppKit 0x00007fff87e41c29 _NSCreateWindowWithOpaqueShape2 + 655
4 AppKit 0x00007fff87e40420 -[NSWindow _commonAwake] + 2002
5 AppKit 0x00007fff87dfee62 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1763
6 AppKit 0x00007fff87dfdfaf -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1568
7 AppKit 0x00007fff87dfd97f -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
8 libSDL-1.2.0.dylib 0x0000000101dc6bf6 -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 279
9 libSDL-1.2.0.dylib 0x0000000101dc4ac9 QZ_SetVideoMode + 2629
10 libSDL-1.2.0.dylib 0x0000000101dbb903 SDL_SetVideoMode + 886
11 test 0x0000000101b9d6b2 smJx_info + 50
)
libc++abi.dylib: terminate called throwing an exception
据我了解,这与main()
有关 - 替换技巧SDL执行。我查看了其他几个使用SDL的Haskell应用程序;我设法编译的那些显示相同的行为(这可能指向我的特定配置的一些问题)。一个例外是Eternal10Seconds,它使用-no-hs-main
ghc选项和一些.c
/ .h
魔法。这是必要的,还是有更明确的方法来使事情有效?
答案 0 :(得分:2)
对不起信息噪音,但我自己设法解决了。似乎.c
魔法是不可避免的,但它需要一些努力才能使它与cabal
一起使用。根据{{3}}和example from haskell-SDL repo,我将TimePiece放在一起。我打算扩展它以使其真正跨平台(因为我自己也需要它)。