Linker error related to atan and ntdll on 32-bit Windows
That's a somewhat confusing title, so let me explain in more detail what I mean.
I first noticed this issue when someone couldn't build Idris on 32-bit Windows (using GHC 7.8, 7.10, or 8.0). Trying to link the Idris executable resulted in this cryptic linker error:
Preprocessing executable 'idris' for idris-0.99.1...
[1 of 1] Compiling Main ( main\Main.hs, dist\build\idris\idris-tmp\Main.o )
Linking dist\build\idris\idris.exe ...
C:/Users/RyanGlScott/Software/ghc-8.0.1-x86/mingw/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(dohds01059.o):(.idata$5+0x0): multiple definition of `_imp__atan'
C:/Users/RyanGlScott/Software/ghc-8.0.1-x86/mingw/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/libntdll.a(dgjjs01967.o):(.idata$5+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
The culprit was apparently Idris's dependency on the mintty package. The important bit was that mintty lists ntdll as in the extra-libraries stanza of its .cabal file. As it turns out, you can also reproduce this with a more recent version of Win32, which also depends on ntdll. First, run these steps:
$ cabal get Win32
$ cd Win32-2.5.2.0/
$ cabal sandbox init
$ cabal install . -w $(pwd)/../../../../Software/ghc-8.0.1-x86/bin/ghc
This will install the recent Win32-2.5.2.0 in a sandbox (NB: I'm using 32-bit Windows GHC 8.0.1 here). Now create this file (which I named Bug.hs):
module Main (main) where
main :: IO ()
main = print (atan 0.5 :: Double)
And you can reproduce the linker error like so:
$ ../../../../Software/ghc-8.0.1-x86/bin/ghc Bug.hs -package-db .cabal-sandbox/i386-windows-ghc-8.0.1-packages.conf.d/ -package Win32 -fforce-recomp
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug.exe ...
C:/Users/RyanGlScott/Software/ghc-8.0.1-x86/mingw/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(dohds01059.o):(.idata$5+0x0): multiple definition of `_imp__atan'
C:/Users/RyanGlScott/Software/ghc-8.0.1-x86/mingw/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/libntdll.a(dgjjs01967.o):(.idata$5+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
It's important to use 32-bit Windows GHC here, since I am unable to reproduce this with 64-bit Windows GHC.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | Phyx- |
| Operating system | |
| Architecture | x86 |