haskell – making windows dll libraries – segfault

Currently, I try to compile my haskell library, which was previously compiled on the arch linux as so. shared library), to windows dll library. I have read, that cabal does not support making haskell dll libraries out of box. According to https://downloads.haskell.org/~ghc/7.0.3/docs/html/users_guide/win32-dlls.html I have compiled such a library to dll (compilation works).

ghc -shared -o libLogic.dll dist/build/HSlogic_KA1QeY80keFKgyu69OtwOE.o  
/c/ghc/ghc-7.10.1/lib/conta_47ajk3tbda43DFWyeF3oHQ/HScontainers-0.5.6.2-47ajk3tbda43DFWyeF3oHQ.o 
.cabal-sandbox/i386-windows-ghc-7.10.1/Missi_1lZqat04J1yLHrfGdhK9Qx/libHSMissingH-1.3.0.1-A2UVxmrfU 
xWGZUHs3Vx4et.a .cabal-sandbox/i386-windows-ghc-7.10.1/text_8rMotiVS8ISBkxP7UzusGU/HStext-1.2.1.1-1L7lZlUz0bO8ROU5DNNfWq.o 
.cabal-sandb ox/i386-windows-ghc-7.10.1/regex_1WudNAZWYEMJ7hjTqevDzK/HSregex-base-0.93.2-CsRFAGo3Jfi7vN1y74K9DT.o 
.cabal-sandbox/i386-windows-ghc-7.10.1/regex_4EmnRBpiUiN81uA3rzCqhM/HSregex-compat-0.95.1-DsaThvjcDpRGceYPQ2iyOg.o 
.cabal-sandbox/i386-windows-ghc-7.10.1/regex_FcyoJ8fpGysAR4JUIv3Onx/HSregex-posix-0.95.2-HrKRtQubtek4GEuR7lgLlg.o /c/ghc/ghc-7.10.1/lib/bytes_6vj5EoliHgNHISHCVCb069/HSbytestring-0.10.6.0-6vj5EoliHgNHISHCVCb069.o 
/c/ghc/ghc-7.10.1/lib/deeps_FpR4obOZALU1lutWnrBldi/HSdeepseq-1.4.1.1-FpR4obOZALU1lutWnrBldi.o 
/c/ghc/ghc-7.10.1/ lib/binar_EKE3c9Lmxb3DQpU0fPtru6/HSbinary-0.7.3.0-EKE3c9Lmxb3DQpU0fPtru6.o  
/c/ghc/ghc-7.10.1/lib/array_FaHmcBFfuRM8kmZLEY8D5S/HSarray-0.5.1.0-FaHmcBFfuRM8kmZLEY8D5S.o  
.cabal-sandbox/i386-windows-ghc-7.10.1/split_EzXNp9Mcx6zDnUvRChe0Sw/HSsplit-0.2.2-EcQml2WFBePDKSCjwazauo.o

This dll library is later used to link program with it (qt project)

win32:LIBS += -L../lcng-gui -lLogic ../lcng-gui/libLogic.dll.a

qt compilation also succeeds, but when I try to run the program – it segfaults in strlen/_mingw_pformat.

What do I wrongly and what can I do to succeed in creating haskell dll library which could be used in any program with which it will be linked?

library
— .hs or .lhs file containing the Main module.
ghc-options:
-O3
-fwarn-unused-imports
extensions: CPP

  -- Modules included in this executable, other than Main.
  -- other-modules:

  -- LANGUAGE extensions used by modules in this package.
  -- other-extensions:

  -- Other library packages from which modules are imported.
  build-depends:       base >=4.8 && <4.9, containers >=0.5 && <0.6,HUnit==1.2.*,split,text,MissingH,parsec >= 3

  -- Directories containing source files.
  hs-source-dirs:      src
  c-sources: src/hsbracket.c
  extra-libraries: HSrts-ghc7.10.1

  -- Base language which the package is written in.
  default-language:    Haskell2010
--  extra-libraries:     libHSrts-ghc7.10.1
  exposed-modules: Bindings,Utils.Expressions,Parser.Expressions,Parser.Tokenizers,
                   Types.Simple,Types.LExpressions,Parser.Operations,
                   Provers.Prover,Utils.Commands,Parser.Simplifiers,
                   Converters.Cnf,Converters.Lcn,Converters.Operators,
                   Utils.Types.LExpressions,Utils.History,Parser.State,
                   Solvers.Cnf,Graphs.Lcn,Utils.Sat,Types.Chess,Graphs.Formula,
                   Graphs.Search,Types.Graphs

and hsbracket is defined accordingly to the ghc documentation:

#include <HsFFI.h>

static void my_enter(void) __attribute__((constructor));
static void my_enter(void)
{
  static char *argv[] = { "libLogic.dll", 0 }, **argv_ = argv;
  static int argc = 1;
  hs_init(&argc, &argv_);
}

static void my_exit(void) __attribute__((destructor));
static void my_exit(void)
{
  hs_exit();
}


Source: windows

Leave a Reply