Skip to content

Runtime linker chokes on object files created by MSVC++

This error prevents the llvm-general library from loading in GHCi on Windows. I don't know how to reproduce this error without using LLVM.

First, you need to install LLVM. On Windows, you can install it with MSYS2:

pacman -S mingw-w64-x86_64-llvm

Currently, this gives you LLVM-3.9, although I've reproduced it with LLVM-3.8 as well.

Now define this Haskell file:

module Main (main) where

import Foreign.C.Types

newtype LLVMBool = LLVMBool CUInt deriving Show

foreign import ccall unsafe "LLVMIsMultithreaded"
  isMultithreaded :: IO LLVMBool

main :: IO ()
main = isMultithreaded >>= print

If you compile it, it works OK:

$ ghc LLVM.hs -fforce-recomp $(llvm-config --libs) $(llvm-config --system-libs) -lstdc++-6 -lgcc_s_seh-1
[1 of 1] Compiling Main             ( LLVM.hs, LLVM.o )
Linking LLVM.exe ...
$ ./LLVM
LLVMBool 1

Or, if you're allergic to llvm-config:

$ ghc LLVM.hs -fforce-recomp -lLLVMLTO -lLLVMObjCARCOpts -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMGlobalISel -lLLVMCoverage -lLLVMTableGen -lLLVMLineEditor -lLLVMOrcJIT -lLLVMMIRParser -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMObjectYAML -lLLVMLibDriver -lLLVMOption -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoCodeView -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMPasses -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMTransformUtils -lLLVMMC -lLLVMBitWriter -lLLVMBitReader -lLLVMAnalysis -lLLVMProfileData -lLLVMCore -lLLVMSupport -lpsapi -lshell32 -lole32 -luuid -lstdc++-6 -lgcc_s_seh-1
[1 of 1] Compiling Main             ( LLVM.hs, LLVM.o )
Linking LLVM.exe ...
$ ./LLVM
LLVMBool 1

If you load it into GHCi, however, things go awry:

$ ghci $(llvm-config --libs) $(llvm-config --system-libs) -lgcc_s_seh-1
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from C:\Users\RyanGlScott\AppData\Roaming\ghc\ghci.conf
Ok, modules loaded: Main (LLVM.o).
> main
ghc.exe: LLVM.o: unknown symbol `LLVMIsMultithreaded'

On GHC 8.0.1 and HEAD, it's a slightly different error:

> main

ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
  LLVMIsMultithreaded
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session.  Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
  glasgow-haskell-bugs@haskell.org
Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System (Linker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC Phyx-
Operating system
Architecture
Edited by Tamar Christina
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information