Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using sdl2: can't load .so/.DLL for: mingw32.dll #41

Closed
MaxDaten opened this issue Feb 9, 2015 · 13 comments
Closed

using sdl2: can't load .so/.DLL for: mingw32.dll #41

MaxDaten opened this issue Feb 9, 2015 · 13 comments
Labels

Comments

@MaxDaten
Copy link

MaxDaten commented Feb 9, 2015

I have currently exactly this problem on Windows 64: http://stackoverflow.com/questions/15996796/haskell-sdl-cant-find-mingw32-dll

building sdl2 from source and hackage is successful, but using it in a project results in a build error during linking:

Loading package sdl2-1.3.0 ...
<no location info>:
    <command line>: can't load .so/.DLL for: mingw32.dll (addDLL: could not load DLL)

<no location info>:
    ghc.exe: panic! (the 'impossible' happened)
  (GHC version 7.8.4 for x86_64-unknown-mingw32):
        Dynamic linker not initialised

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

some ideas whats the problem here or how to workaround it? A mingw32.dll does not exist, I think the lib is statically linked in and is not meant to be dynamically.

I wrote it here (fpco/minghc#28) too, because I'm using minghc 7.8.4 64bit on windows, but I think it's not minghc related.

@Kludgy
Copy link

Kludgy commented Feb 9, 2015

This is a long standing problem with the GHCi linker:

https://ghc.haskell.org/trac/ghc/ticket/3242

You will encounter the error loading into GHCi, or compiling a TH project
requiring a mingw deoendency. Mingw32.dll does not exist.

I'm currently gathering a more complete story on tge GHC dev side, but
there are linking issues beyond just skipping the addDLL call.

Cheers,
Darren
On Feb 9, 2015 7:22 AM, "Jan-Philip Loos" notifications@github.com wrote:

I have currently exactly this problem on Windows 64:
http://stackoverflow.com/questions/15996796/haskell-sdl-cant-find-mingw32-dll

building sdl2 from source and hackage is successful, but using it in a
project results in a build error during linking:

Loading package sdl2-1.3.0 ...
:
: can't load .so/.DLL for: mingw32.dll (addDLL: could not load DLL)

:
ghc.exe: panic! (the 'impossible' happened)
(GHC version 7.8.4 for x86_64-unknown-mingw32):
Dynamic linker not initialised

Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug

some ideas whats the problem here or how to workaround it? A mingw32.dll
does not exist, I think the lib is statically linked in and is not meant to
be dynamically.

I wrote it here http:///fpco/minghc/#5 too, because I'm using minghc
7.8.4 64bit on windows, but I think it's not minghc related.


Reply to this email directly or view it on GitHub
#41.

@MaxDaten
Copy link
Author

MaxDaten commented Feb 9, 2015

so there is no current solution or a dirty workaround for it beside dumping TH in my project? With the result that this problem will block my project completely from windows? :(

Anyway thanks for the reply, and good luck with fixing it (hopefully soon :P)

@mtolly
Copy link

mtolly commented Jun 23, 2015

Has any progress been made on this? I can work around loading sdl2 during TH by making a separate package with the TH stuff, but it'd be nice not to have to.

I have sdl2 installed via msys2. The -lmingw32 shows up in 4 places. Twice in C:\msys32\mingw32\bin\sdl2-config:

    --libs)
      echo -L${exec_prefix}/lib  -lmingw32 -lSDL2main -lSDL2  -mwindows
      ;;
    --static-libs)
#    --libs|--static-libs)
      echo -L${exec_prefix}/lib  -lmingw32 -lSDL2main -lSDL2  -mwindows  -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
      ;;

and twice in C:\msys32\mingw32\lib\pkgconfig\sdl2.pc:

Libs: -L${libdir}  -lmingw32 -lSDL2main -lSDL2  
Libs.private: -lmingw32 -lSDL2main -lSDL2    -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc
Cflags: -I${includedir}/SDL2  -Dmain=SDL_main

Of these 4, the third one (Libs: -L${libdir} -lmingw32 -lSDL2main -lSDL2) appears to be the important one. If I remove the other 3, sdl2 still builds, but TH fails due to mingw32.dll. If I remove the third one, then sdl2 itself fails to build:

Resolving dependencies...
Configuring sdl2-1.3.1...
Building sdl2-1.3.1...
Preprocessing library sdl2-1.3.1...
C:/Program Files/Haskell Platform/2014.2.0.0/mingw/bin/../lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
linking dist\dist-sandbox-27fcd51a\build\Graphics\UI\SDL\Enum_hsc_make.o failed (exit code 1)
command was: C:\Program Files\Haskell Platform\2014.2.0.0\mingw\bin\gcc.exe dist\dist-sandbox-27fcd51a\build\Graphics\UI\SDL\Enum_hsc_make.o dist\dist-sandbox-27fcd51a\build\Graphics\UI\SDL\Enum_hsc_utils.o -o dist\dist-sandbox-27fcd51a\build\Graphics\UI\SDL\Enum_hsc_make.exe -LC:/msys32/mingw32/lib -lSDL2 -lSDL2main -lSDL2 -LC:\msys32\home\Administrator\jelly\.cabal-sandbox\i386-windows-ghc-7.8.3\transformers-0.4.3.0 -LC:\Program Files\Haskell Platform\2014.2.0.0\lib\base-4.7.0.1 -lwsock32 -luser32 -lshell32 -LC:\Program Files\Haskell Platform\2014.2.0.0\lib\integer-gmp-0.5.1.0 -LC:\Program Files\Haskell Platform\2014.2.0.0\lib\ghc-prim-0.3.1.0 -LC:\Program Files\Haskell Platform\2014.2.0.0\lib/rts-1.0 -lm -lwsock32 -lgdi32 -lwinmm
Failed to install sdl2-1.3.1
cabal.exe: Error: some packages failed to install:
sdl2-1.3.1 failed during the building phase. The exception was:
ExitFailure 1
sdl2-image-0.1.3.1 depends on sdl2-1.3.1 which failed to install.

mingw32 of course only exists as a static library, located at C:\msys32\mingw32\i686-w64-mingw32\lib\libmingw32.a and C:\Program Files\Haskell Platform\2014.2.0.0\mingw\lib\libmingw32.a.

@nxths
Copy link
Contributor

nxths commented Sep 14, 2015

As of sdl2-2.0.0 I can build and link as a 64-bit library without encountering this error. See the 64-bit note + Steps 1-5 of https://www.reddit.com/r/haskellgamedev/comments/3kvm7z/building_and_installing_sdl2_200_sdl2image/

@mtolly
Copy link

mtolly commented Sep 14, 2015

I'm not able to follow that exact set of instructions, but yes, I do still have this problem with sdl2-2.0.0. To be clear, this is a problem that comes up only when using Template Haskell in a module that also depends on sdl2, or when running a module that depends on sdl2 in ghci. Here's a setup using msys2 and stack that fails for me (I'm using Windows XP 32-bit):

sdl2test.cabal

name:                sdl2test
version:             0.1.0.0
build-type:          Simple
cabal-version:       >=1.10

executable sdl2test
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010
  build-depends:       base >= 4.7 && < 5, sdl2 == 2.0.0

stack.yaml

extra-deps:
- sdl2-2.0.0
resolver: lts-3.5
flags: {}
packages:
- '.'

src/Main.hs

{-# LANGUAGE TemplateHaskell #-}
module Main where

import SDL

$(return [])

main :: IO ()
main = putStrLn "hello world"

Steps to reproduce:

$ pacman -S mingw32/mingw-w64-i686-SDL2 mingw32/mingw-w64-i686-pkg-config
...
$ PATH="/mingw32/bin/:$PATH" stack build --extra-lib-dirs=/mingw32/lib --extra-include-dirs=/mingw32/include/SDL2
...
Configuring sdl2test-0.1.0.0...
sdl2test-0.1.0.0: build
Preprocessing executable 'sdl2test' for sdl2test-0.1.0.0...
[1 of 1] Compiling Main             ( src\Main.hs, .stack-work\dist\i386-windows\Cabal-1.22.4.0\build\sdl2test\sdl2test-tmp\Main.o )
<command line>: can't load .so/.DLL for: mingw32.dll (addDLL: could not load DLL)
ghc.exe: mingw32: The specified module could not be found.

--  While building package sdl2test-0.1.0.0 using:
      C:\Documents and Settings\Administrator\Application Data\stack\setup-exe-cache\setup-Simple-Cabal-1.22.4.0-i386-windows-ghc-7.10.2.exe --builddir=.stack-work\dist\i386-windows\Cabal-1.22.4.0\ build exe:sdl2test --ghc-options -hpcdir .stack-work\dist\i386-windows\Cabal-1.22.4.0\hpc\.hpc\ -ddump-hi -ddump-to-file
    Process exited with code: ExitFailure 1

Or, remove the Template Haskell lines from src/Main.hs, but then instead of stack build for the last command, run stack ghci. Same error occurs.

Again, without the TH usage, and outside of ghci, everything works fine.

I have not tried this all in 64-bit yet -- I can maybe do that soon once I get a 64-bit Windows VM set up.

@nxths
Copy link
Contributor

nxths commented Sep 14, 2015

@mtolly apologies I misread the original post, didn't realize TH was being used in the linked project, not the bindings themselves. Ignore my post, this will keep occurring until the linked GHC ticket above is fixed

@akhra
Copy link
Collaborator

akhra commented Oct 31, 2015

Good news!

@Kludgy
Copy link

Kludgy commented Oct 31, 2015

Well that's something fantastic! Going to try this when I get home.
On Oct 31, 2015 20:49, "tejon" notifications@github.com wrote:

Good news! https://ghc.haskell.org/trac/ghc/ticket/3242#comment:40


Reply to this email directly or view it on GitHub
#41 (comment).

@Mistuke
Copy link

Mistuke commented Mar 31, 2016

Hi, as you've probably noticed, the previous patch wasn't enough to get sdl2 working in GHCi on Windows. While it's able to find mingw32 now it still can't successfully link it.
This however should be fixed soon when this patch is merged.

@Mistuke
Copy link

Mistuke commented Apr 17, 2016

The patch has been merged into GHC 8. sdl2 should work fine in it.

@nitrix
Copy link

nitrix commented Aug 28, 2016

Bringing this to light; since GHC 8, the story has vastly improved and this task became irrelevant. @MaxDaten could confirm that using GHC 8 the problems are gone (as is the case for everyone), then we could close this (:

@mtolly
Copy link

mtolly commented Aug 29, 2016

I can confirm that my test case above works (updated to use stack resolver nightly-2016-08-29 and sdl2-2.1.2.1).

@akhra
Copy link
Collaborator

akhra commented Aug 29, 2016

Hooray! Closing this.

@akhra akhra closed this as completed Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants