GHCi linker (which is used by TH) cannot load some C++ code dynamically for some reason. It's unclear whether these GHC tickets are really fixed: GHC 3242, GHC 10726.
Workaround:
- Put list of unresolved externals into all.def (add others if needed):
EXPORTS
__mingw_vsprintf
__mingw_vsnprintf
strdup
__popcountdi2
snprintf
mingw_getsp
_Unwind_Resume
- Perform:
stack exec gcc -- all.def -shared -oall.dll
- Put all.dll into GHC lib path (mingw/lib).
- Add
extra-ghci-libraries: all
to package which uses C++.
EXPORTS
__mingw_vsprintf
__mingw_vsnprintf
strdup
__popcountdi2
snprintf
mingw_getsp
__gxx_personality_sj0
_Unwind_SjLj_Register
_Unwind_SjLj_Unregister
_Unwind_SjLj_Resume
stack exec gcc -- all.def -lstdc++ -shared -oall.dll
Plus in GHC 7.10.1 there's a bug leading to compiler crash with message like: checkProddableBlock: invalid fixup in runtime linker
. The workaround I know is to patch GHC:
diff --git a/rts/Linker.c b/rts/Linker.c
index 0bd2aa8..18762f6 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -4684,7 +4684,7 @@ ocResolve_PEi386 ( ObjectCode* oc )
foundit:;
}
/* All supported relocations write at least 4 bytes */
- checkProddableBlock(oc, pP, 4);
+ // checkProddableBlock(oc, pP, 4); // commented by quyse
switch (reltab_j->Type) {
#if defined(i386_HOST_ARCH)
case MYIMAGE_REL_I386_DIR32:
Looks like all you need is
EXPORTS
__popcountdi2
__mingw_strtod
_ZdlPv
__cxa_pure_virtual
__mingw_strtod
is apparently needed for some C code, specifically lua reference implementation.
_ZdlPv
and __cxa_pure_virtual
are needed for C++ code (libsquish
in flaw-asset-dxt
).
stack exec curl -- -O http://libsdl.org/release/SDL2-2.0.3.zip
stack exec bash -- ./configure --build=x86_64-w64-mingw32 --disable-directx --disable-render-d3d --prefix=/
stack exec make
Well, doesn't work, stack doesn't want to pick it up.
New workaround for C++ linking errors:
if os(windows)
if arch(x86_64)
extra-ghci-libraries: gcc_s_seh-1
else
extra-ghci-libraries: gcc_s_dw2-1
Also compilation crashes. Workaround is to use -fexternal-interpreter.
ghc-options:
"*": -O3 -threaded -with-rtsopts=-N -Wall -fno-warn-unsupported-calling-conventions -fno-warn-tabs -fexternal-interpreter
rebuild-ghc-options: true
apply-ghc-options: everything
dump-logs: all
build:
split-objs: true